robnik
1
I know how to get an instance of a metatype...
let t = type(of: obj) // or...
let t = SomeType.self
But is there a way to check another instance obj2 to see if it is assignable to that type t? I can say t == type(of: obj2) but that doesn't account for subclasses and protocols.
Rob
If you want to use a constant or variable as a type, you won't be able to use type casting. But you can use
conforms(to:) or isKind(of:)
However, keep in mind that often when this question arises, there is something wrong in the approach used.