Created
March 31, 2016 14:34
-
-
Save wh1pch81n/be2720f7badf3fbcbf17291811e5ff62 to your computer and use it in GitHub Desktop.
In swift, if you instantiate the view controller from the storyboard identifier, you typically need to cast it. However, since the storyboard identifier is typically the same as the vc name, it might be perfectly acceptable to just pass in the type and convert that to a string. Since you passed in a type, the function can infer the return type.
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
extension UIStoryboard { | |
func instantiateViewControllerWithTypeAsIdentifier<T>(t: T.Type) -> T { | |
return instantiateViewControllerWithIdentifier(String(t)) as! T | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment