rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
264 stars 63 forks source link

UIStoryboard extension #28

Closed pMalvasio closed 7 years ago

pMalvasio commented 7 years ago

Add extension to instantiate controllers using generics

extension UIStoryboard {

    public class func instantiateViewController <T: UIViewController>(_ type: T.Type, storyboardIdentifier: String = "Main") -> T? {
        let storyboard = UIStoryboard(name: storyboardIdentifier, bundle: nil)
        return storyboard.instantiateViewController(type)
    }

    public func instantiateViewController <T: UIViewController>(_ type: T.Type) -> T? {
        return instantiateViewController(withIdentifier: String(describing: type)) as? T
    }
}