Advertisement
DanielGrimm

Untitled

Feb 19th, 2022
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.98 KB | None | 0 0
  1. //
  2. //  StoryboardAble.swift
  3. //
  4. import UIKit
  5.  
  6. protocol StoryboardAble {
  7.    
  8.     static var storyboardName: String { get }
  9.     static var storyboardBundle: Bundle { get }
  10.     static var storyboardIdentifier: String { get }
  11.    
  12.     static func instantiate() -> Self
  13. }
  14.  
  15. extension StoryboardAble where Self: UIViewController {
  16.    
  17.     static var storyboardName: String {
  18.         return "Main"
  19.     }
  20.    
  21.     static var storyboardBundle: Bundle {
  22.         return .main
  23.     }
  24.    
  25.     static var storyboardIdentifier: String {
  26.         return String(describing: self)
  27.     }
  28.    
  29.     static func instantiate() -> Self {
  30.        
  31.         guard let viewController = UIStoryboard(name: storyboardName, bundle: storyboardBundle).instantiateViewController(withIdentifier: storyboardIdentifier) as? Self else {
  32.             fatalError("Unable to Instantiate View Controller With Storyboard Identifier \(storyboardIdentifier)")
  33.         }
  34.        
  35.         return viewController
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement