I'm trying to switch on a type in swift. I'm not trying to switch on the type of an object instance, I'm trying to switch on the actual type itself. For example:
let t: Any.Type = Int.self
switch t {
case is Int:
print("int")
default:
print("other")
}
I would expect this to print "int" but it falls into the default case.
I can accomplish the desired result with an if statement, as in,
if t == Int.self
{
print("t is an int")
}
but I was hoping for a way to do this with a switch. I've read Apple's 'Type Casting' documentation, perhaps not thoroughly enough because I can't see a way to apply it here.