Created
March 22, 2018 18:33
-
-
Save brunogama/a3f7520c9727bc3d134818658fcae5dd to your computer and use it in GitHub Desktop.
UIViewController+StoryboardInstantiable
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
public protocol StoryboardInstantiable: class { | |
static func fromStoryboard(name: String, bundle: Bundle?) -> Self | |
} | |
extension StoryboardInstantiable where Self: UIViewController { | |
static func fromStoryboard(name: String = "Main", bundle: Bundle? = nil) -> Self { | |
let identifier = String(describing: self) | |
let storyboard = UIStoryboard(name: name, bundle: bundle) | |
guard let viewController = | |
storyboard.instantiateViewController(withIdentifier: identifier) as? Self else { | |
fatalError("Cannot instantiate view controller of type " + identifier) | |
} | |
return viewController | |
} | |
} |
this is a new message
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This might be useful somehow