Last active
August 25, 2021 13:22
-
-
Save thomsmed/a2ac8f4374e9765f18fc7fef720e058f to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// UIStoryboard+Extensions.swift | |
// | |
import Foundation | |
import UIKit | |
extension UIStoryboard { | |
static func instantiate<T>(fromStoryboardWithName name: String = "Main", inBundle bundle: Bundle = .main) -> T where T: UIViewController { | |
let identifier = String(describing: T.self) | |
if let viewController = UIStoryboard(name: name, bundle: bundle).instantiateViewController(identifier: identifier) as? T { | |
return viewController | |
} | |
fatalError("Could not instantiate view controller of type \(identifier) with identifier \(identifier) from storyboard with name \(name) in bundle at \(bundle.bundlePath)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment