Last active
May 23, 2018 04:14
-
-
Save jay18001/b19b5cd3360e10238a7ccff1873231f2 to your computer and use it in GitHub Desktop.
Protocol StoryboardInitialization
This file contains hidden or 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 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