I'm looking to try and cast a type based on a variable. The example below fails saying "Use of undeclared type, 'myType'"
protocol Parent {}
protocol Child: Parent {}
struct Foo: Child {}
let foo: Parent = Foo()
let myType = Child.self
if let _ = foo as? myType {
print("success")
}
Is there any way to cast based on the variable myType
?
Having reflected, casting is not the right question to ask here. Here i'm just checking for conformance. Dynamic casting would be useless as there's no way for the static analyzer to know what to do with it if it's casting based on a variable type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With