Last active
April 15, 2016 07:57
-
-
Save vibrazy/a61748c2b3cce26cdc0b7f82ae3e045d to your computer and use it in GitHub Desktop.
Generic UIStoryboardSegue Extension for Loading destinationViewController
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 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