Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import UIKit
  2.  
  3. extension UIStoryboard {
  4. enum Storyboard: String {
  5. case Main
  6. // TODO add all the project storyboards here
  7. }
  8.  
  9. convenience init(storyboard: Storyboard, bundle: NSBundle? = nil) {
  10. self.init(name: storyboard.rawValue, bundle: bundle)
  11. }
  12.  
  13. func instantiateViewController<VC: UIViewController where VC: StoryboardIdentifiable>() -> VC {
  14. let optionalViewController = self.instantiateViewControllerWithIdentifier(VC.storyboardIdentifier)
  15.  
  16. guard let viewController = optionalViewController as? VC else {
  17. fatalError("Couldn't instantiate view controller with identifier \(VC.storyboardIdentifier) ")
  18. }
  19.  
  20. return viewController
  21. }
  22. }
  23.  
  24. protocol StoryboardIdentifiable {
  25. static var storyboardIdentifier: String { get }
  26. }
  27.  
  28. extension StoryboardIdentifiable where Self: UIViewController {
  29. static var storyboardIdentifier: String {
  30. return String(self)
  31. }
  32. }
  33.  
  34. extension UIViewController : StoryboardIdentifiable { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement