Skip to content

Instantly share code, notes, and snippets.

@fisherds
Last active March 1, 2018 14:54
Show Gist options
  • Select an option

  • Save fisherds/9eda9a5543fbf76266fa to your computer and use it in GitHub Desktop.

Select an option

Save fisherds/9eda9a5543fbf76266fa to your computer and use it in GitHub Desktop.
Code used in our Swift Playgrounds lecture
// Basic enum
enum Weekday {
case monday, tuesday, wednesday, thursday, friday
}
var today: Weekday
today = .thursday
//today.rawValue // Enum was not given a rawValue Type (see State below)
switch today {
case .monday, .tuesday, .thursday:
print("You have class!")
case .wednesday:
print("Weekend Wednesday!")
default:
print("Enjoy the weekend!")
}
// Rawvalues
enum State : Int {
case ready = 0
case set
case go
}
var raceState = State.set
raceState.rawValue
var nextRaceState = State(rawValue: raceState.rawValue + 1)
if nextRaceState == .go {
print("Go! Go! Go!")
}
nextRaceState
nextRaceState?.rawValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment