In swift the if let syntax allows me to only execute statements if a variable is of a certain type. For example
class A {...}
class B: A {...}
class C: A {...}
func foo(thing: A) {
if let b = thing as? B {
// do something
}else if let c = thing as? C {
// do something else
}
}
Is it possible to achieve this with a switch statement?
I have got this far, but the variables b and c are still of type A, not cast to B and C:
func foo(thing: A) {
switch thing {
case let b where b is B:
// do something
case let c where c is C:
// do something else
default:
// do something else:
}
}