Back to questions
JuniorTheoryCommon
What does the program print?
enum Dish: Int {
case soup = 1, salad, pasta = 10, cake
}
print(Dish.salad.rawValue, Dish.cake.rawValue)2 11
- Expecting
2 4: counting every case by position from the first number. An explicit value such aspasta = 10restarts the count, so the next case gets11. - Expecting raw values to be positions from zero, like array indices: an
Intenum starts from0only when its first case has no explicit number.
- What does
Dish(rawValue: 3)return, and why is the result optional? - Which raw value would
soupget without= 1?