Predict the output
What does this print?
enum Planet: Int {
case mercury = 1, venus, earth
}
print(Planet.earth.rawValue)
print(Planet(rawValue: 7) == nil)Hint 1 of 1
What raw value does venus get?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B 3 then true
Correct. earth is 3, and there is no case with raw value 7.
Why not the others?
- A 2 then false. Raw values start at 1 and count up, so earth is 3.
- C 3 then false.
init(rawValue:)returns nil for unknown values. - D It doesn't compile. Implicit raw values for Int enums are allowed.