Here's some strange behavior, I have a value of type Any
and I wish to switch on it's protocol conformance, and when the real type of the value is optional, it does not work:
let something: Int? = 42
switch something {
case let x as Equatable: print("Yeepee! The answer is \(x)") // Here's what is matched
default: print("Boohoo!")
}
let anything: Any = something // anything contains a Int? value
switch anything {
case let x as Equatable: print("Yeepee! The answer is \(x)")
default: print("Boohoo!") // Here's what is matched
}
First I simply do not understand why the behavior is different, then how can I make the second switch match correctly the value, even if it's optional?
Thanks in advance.