Skip to content

Instantly share code, notes, and snippets.

@thomsmed
Last active August 25, 2021 13:22
Show Gist options
  • Save thomsmed/a2ac8f4374e9765f18fc7fef720e058f to your computer and use it in GitHub Desktop.
Save thomsmed/a2ac8f4374e9765f18fc7fef720e058f to your computer and use it in GitHub Desktop.
//
// 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