Last active
August 29, 2015 14:25
-
-
Save tomkowz/f04d19b115211cd0be6c to your computer and use it in GitHub Desktop.
String Enum in Xcode 7 beta 3
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
| enum GameState { | |
| case NotStarted | |
| case InPlay | |
| case GameWon | |
| case PlayingForHigherScores | |
| case GameLost | |
| func simpleDescription(state: GameState) -> String { | |
| switch state { | |
| case .NotStarted: | |
| return "NotStarted" | |
| case .InPlay: | |
| return "InPlay" | |
| case .GameWon: | |
| return "GameWon" | |
| case .PlayingForHigherScores: | |
| return "PlayingForHigherScores" | |
| case .GameLost: | |
| return "GameLost" | |
| } | |
| } | |
| func description() -> String { | |
| return self.simpleDescription(self) | |
| } | |
| } | |
| // Xcode 7 beta 3 updated Swift 2.0 and it copies name of a case to its raw value. | |
| // It should look like this: | |
| enum GameState: String { | |
| case NotStarted // rawValue = "NotStarted", the same with other cases | |
| case InPlay | |
| case GameWon | |
| case PlayingForHigherScores | |
| case GameLost | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment