Skip to content

Instantly share code, notes, and snippets.

@jay18001
Last active May 23, 2018 04:14
Show Gist options
  • Save jay18001/b19b5cd3360e10238a7ccff1873231f2 to your computer and use it in GitHub Desktop.
Save jay18001/b19b5cd3360e10238a7ccff1873231f2 to your computer and use it in GitHub Desktop.
Protocol StoryboardInitialization
public protocol StoryboardInitialization {
static var storyboardIdentifier: String { get }
}
public extension UIStoryboard {
public func instantiateViewController<T: StoryboardInitialization>(withType classIdent: T.Type) -> T? {
return self.instantiateViewController(withIdentifier: classIdent.storyboardIdentifier) as? T
}
}
//Usage
storyboard?.instantiateViewController(withType: ViewController.self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment