Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunogama/a3f7520c9727bc3d134818658fcae5dd to your computer and use it in GitHub Desktop.
Save brunogama/a3f7520c9727bc3d134818658fcae5dd to your computer and use it in GitHub Desktop.
UIViewController+StoryboardInstantiable
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
}
}
@brunogama
Copy link
Author

This might be useful somehow

@brunogama
Copy link
Author

this is a new message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment