Skip to content

Instantly share code, notes, and snippets.

@mattdenner
Last active July 21, 2022 13:20
Show Gist options
  • Save mattdenner/643f17ad52c374510a8c to your computer and use it in GitHub Desktop.
Save mattdenner/643f17ad52c374510a8c to your computer and use it in GitHub Desktop.
Segues using enums in Swift
extension UIViewController {
func performSegue<T:RawRepresentable where T.RawValue==String>(identifier: T, sender: AnyObject?)
self.performSegueWithIdentifier(identifier.rawValue, sender: sender)
}
}
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