Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- extension UIStoryboard {
- enum Storyboard: String {
- case Main
- // TODO add all the project storyboards here
- }
- convenience init(storyboard: Storyboard, bundle: NSBundle? = nil) {
- self.init(name: storyboard.rawValue, bundle: bundle)
- }
- func instantiateViewController<VC: UIViewController where VC: StoryboardIdentifiable>() -> VC {
- let optionalViewController = self.instantiateViewControllerWithIdentifier(VC.storyboardIdentifier)
- guard let viewController = optionalViewController as? VC else {
- fatalError("Couldn't instantiate view controller with identifier \(VC.storyboardIdentifier) ")
- }
- return viewController
- }
- }
- protocol StoryboardIdentifiable {
- static var storyboardIdentifier: String { get }
- }
- extension StoryboardIdentifiable where Self: UIViewController {
- static var storyboardIdentifier: String {
- return String(self)
- }
- }
- extension UIViewController : StoryboardIdentifiable { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement