I'm probably missing something obvious here, but I'm wondering why using a switch with enum cases doesn't work:
protocol IntegerComparableEnum {
var rawValue: Int { get }
}
func ~= (pattern: IntegerComparableEnum, value: Int) -> Bool {
return pattern.rawValue == value
}
enum Foobar: Int, IntegerComparableEnum {
case Zero, One, Two
}
// "enum case 'Zero' is not a member of type 'Int'
switch someValue {
case Foobar.Zero: print("0")
case Foobar.First: print("1")
case Foobar.Second: print("2")
}when using the the pattern matching operator manually it works as expected:
let someValue = 1
let result = Foobar.One ~= someValue
print("result is \(result)") // prints "result is true"Any idea what I'm doing wrong in the first case?
Thanks,
Axel