Created
February 4, 2018 20:16
-
-
Save twittemb/1e1bc5def144d14e3e7f7f26f777088b to your computer and use it in GitHub Desktop.
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 StoryboardBased: class { | |
| static var storyboard: UIStoryboard { get } | |
| } | |
| public extension StoryboardBased { | |
| static var storyboard: UIStoryboard { | |
| return UIStoryboard(name: String(describing: self), bundle: Bundle(for: self)) | |
| } | |
| } | |
| public extension StoryboardBased where Self: UIViewController { | |
| static func instantiate() -> Self { | |
| guard let vc = storyboard.instantiateInitialViewController() as? Self else { | |
| fatalError("The VC of \(sceneStoryboard) is not of class \(self)") | |
| } | |
| return vc | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment