#10: Raw Values
Question
// Swift Quiz
— objc.io (@objcio) April 24, 2019
enum Foo: RawRepresentable {
case one
case two
init?(rawValue: Int) {
self = .one
}
var rawValue: Int {
return 1
}
}
switch Foo.two {
case .one: print("1")
case .two: print("2")
}
// What's the output?
Solution
Solution: 2
— objc.io (@objcio) April 25, 2019
Although all cases have a raw value of 1, the .two case matches.
Switching over an enum does not use its raw value for matching.https://t.co/s7500CWmAg