Created
August 23, 2016 17:07
This gist is to demonstrate instanceType alternative in Swift. Credits to Martin R (StackOverflow)
This file contains hidden or 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
extension UIViewController | |
{ | |
class func instantiateFromStoryboard(storyboardName: String, storyboardId: String) -> Self | |
{ | |
return instantiateFromStoryboardHelper(storyboardName, storyboardId: storyboardId) | |
} | |
private class func instantiateFromStoryboardHelper<T>(storyboardName: String, storyboardId: String) -> T | |
{ | |
let storyboard = UIStoryboard(name: storyboardName, bundle: nil) | |
let controller = storyboard.instantiateViewControllerWithIdentifier(storyboardId) as! T | |
return controller | |
} | |
} | |
let vc = MyViewController.instantiateFromStoryboard("name", storyboardId: "id") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment