Skip to content

Instantly share code, notes, and snippets.

@vibrazy
Last active April 15, 2016 07:57
Show Gist options
  • Select an option

  • Save vibrazy/a61748c2b3cce26cdc0b7f82ae3e045d to your computer and use it in GitHub Desktop.

Select an option

Save vibrazy/a61748c2b3cce26cdc0b7f82ae3e045d to your computer and use it in GitHub Desktop.
Generic UIStoryboardSegue Extension for Loading destinationViewController
extension UIStoryboardSegue {
/*
Generic way of loading destinationViewController
Usage:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let controller = segue.destinationController("SegueName", type: CustomController.self) {
print(controller)
}
}
*/
func destinationController<T>(identifier: String, type: T.Type) -> T? {
guard let controller = self.destinationViewController as? T
where self.identifier == identifier else {
return nil
}
return controller as T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment