Forked from jckarter/gist:53fcd4046e2857bd315b
Last active
November 14, 2016 11:32
-
-
Save ManWithBear/cd482b0b839eb8e583328379accc989f to your computer and use it in GitHub Desktop.
Optional chaining raw value conversion
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 String { | |
func toEnum<Enum: RawRepresentable where Enum.RawValue == String>() -> Enum? { | |
return Enum(rawValue: self) | |
} | |
} | |
enum Segue: String { | |
case Foo | |
case Bar | |
} | |
let x: String = "Foo" | |
let y: Segue? = x.toEnum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment