Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // StoryboardAble.swift
- //
- import UIKit
- protocol StoryboardAble {
- static var storyboardName: String { get }
- static var storyboardBundle: Bundle { get }
- static var storyboardIdentifier: String { get }
- static func instantiate() -> Self
- }
- extension StoryboardAble where Self: UIViewController {
- static var storyboardName: String {
- return "Main"
- }
- static var storyboardBundle: Bundle {
- return .main
- }
- static var storyboardIdentifier: String {
- return String(describing: self)
- }
- static func instantiate() -> Self {
- guard let viewController = UIStoryboard(name: storyboardName, bundle: storyboardBundle).instantiateViewController(withIdentifier: storyboardIdentifier) as? Self else {
- fatalError("Unable to Instantiate View Controller With Storyboard Identifier \(storyboardIdentifier)")
- }
- return viewController
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement