Skip to content

Instantly share code, notes, and snippets.

@tomkowz
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save tomkowz/f04d19b115211cd0be6c to your computer and use it in GitHub Desktop.

Select an option

Save tomkowz/f04d19b115211cd0be6c to your computer and use it in GitHub Desktop.
String Enum in Xcode 7 beta 3
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