Created
September 12, 2015 03:56
-
-
Save asmallteapot/579d69412bb86e1f127f to your computer and use it in GitHub Desktop.
Handling storyboard segues with enumerations in Swift
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
class MonolithViewController: UIViewController { | |
enum InnerSegueType { | |
case WebView | |
case Inspector | |
static func match(segue: UIStoryboardSegue, _ sender: AnyObject?) -> InnerSegueType? { | |
if segue.identifier == "WebView" { | |
return .WebView | |
} | |
if segue.identifier == "Inspector" { | |
return .Inspector | |
} | |
return nil | |
} | |
} | |
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
guard let segueType = InnerSegueType.match(segue, sender) else { | |
return | |
} | |
switch segueType { | |
case .WebView: | |
print("configure web view controller") | |
case .Inspector: | |
print("configure inspector") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you still looking for feedback on this? You could make the enum back by a String and use its constructor to get the enum value.
Something like that maybe?