Last active
June 7, 2021 12:10
-
-
Save alexj70/9814b431086e1e3deeb3f4c2976703f8 to your computer and use it in GitHub Desktop.
UIStoryboard extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIStoryboard { | |
/// Main storyboard | |
public var main: UIStoryboard { | |
return UIStoryboard(name: "Main", bundle: nil) | |
} | |
/// Instantiates and returns the view controller with the specified identifier. | |
/// | |
/// - Parameter identifier: uniquely identifies equals to Class name | |
/// - Returns: The view controller corresponding to the specified identifier string. If no view controller is associated with the string, this method throws an exception. | |
public func instantiateViewController<T>(withIdentifier identifier: T.Type) -> T where T: UIViewController { | |
let className = String(describing: identifier) | |
guard let vc = self.instantiateViewController(withIdentifier: className) as? T else { | |
fatalError("Cannot find controller with identifier \(className)") | |
} | |
return vc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment