Skip to content

Instantly share code, notes, and snippets.

@mwrites
Created July 19, 2016 05:46
Show Gist options
  • Save mwrites/0c895deaeaa1a5de0966b77879c478d6 to your computer and use it in GitHub Desktop.
Save mwrites/0c895deaeaa1a5de0966b77879c478d6 to your computer and use it in GitHub Desktop.
extension UIStoryboard {
static func main() -> UIStoryboard {
return UIStoryboard(name: "Main", bundle: nil)
}
// assuming that name of the class is the identifier
static func controllerOfType<C where C : UIViewController> (type : C.Type) -> C {
let name = String(type)
let vc = UIStoryboard.main().instantiateViewControllerWithIdentifier(name)
let instance = vc as! C
return instance
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment