Created
May 10, 2016 11:09
-
-
Save bmoliveira/b932c659312bba4b6080e39653d827f1 to your computer and use it in GitHub Desktop.
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
protocol SegueHandlerType { | |
associatedtype SegueIdentifier: RawRepresentable | |
} | |
// notice the cool use of where here to narrow down | |
// what could use these methods. | |
extension SegueHandlerType where Self: UIViewController, | |
SegueIdentifier.RawValue == String | |
{ | |
func performSegueWithIdentifier(segueIdentifier: SegueIdentifier, | |
sender: AnyObject?) { | |
performSegueWithIdentifier(segueIdentifier.rawValue, sender: sender) | |
} | |
func segueIdentifierForSegue(segue: UIStoryboardSegue) -> SegueIdentifier { | |
// still have to use guard stuff here, but at least you're | |
// extracting it this time | |
guard let identifier = segue.identifier, | |
segueIdentifier = SegueIdentifier(rawValue: identifier) else { | |
fatalError("Invalid segue identifier \(segue.identifier).") } | |
return segueIdentifier | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment