Last active
March 1, 2018 14:54
-
-
Save fisherds/9eda9a5543fbf76266fa to your computer and use it in GitHub Desktop.
Code used in our Swift Playgrounds lecture
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
| // 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