Last active
July 21, 2022 13:20
-
-
Save mattdenner/643f17ad52c374510a8c to your computer and use it in GitHub Desktop.
Segues using enums 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
extension UIViewController { | |
func performSegue<T:RawRepresentable where T.RawValue==String>(identifier: T, sender: AnyObject?) | |
self.performSegueWithIdentifier(identifier.rawValue, sender: sender) | |
} | |
} |
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 MyViewController: UIViewController { | |
enum Segue: String { | |
case GoThere = "go-via-this-segue" | |
case GoSomewhere = "go-via-that-segue" | |
} | |
@IBAction func clickButton(sender: UIButton) { | |
self.performSegue(Segue.GoThere, sender: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment