Last active
November 13, 2017 23:26
-
-
Save moaible/fb5a56519ed5999d36785a166503a1ef to your computer and use it in GitHub Desktop.
StoryboardInstantiate.swift
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
| import UIKit | |
| protocol StoryboardInstantiate { | |
| static var storyboardIdentifier: String { get } | |
| static var storyboardName: String { get } | |
| } | |
| extension UIStoryboard { | |
| static func instantiateViewController<ViewController: UIViewController>() -> ViewController where ViewController: StoryboardInstantiate { | |
| let storyboard = UIStoryboard(name: ViewController.storyboardName, bundle: nil) | |
| let viewController = storyboard.instantiateViewController(withIdentifier: ViewController.storyboardIdentifier) | |
| guard let instantiatedViewController = viewController as? ViewController else { | |
| fatalError("Unmatche ViewController class: \(type(of: viewController))") | |
| } | |
| return instantiatedViewController | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment