How do you arbitrarily apply a type variable

I am trying to apply a variable based type. The example below does not say "Using an 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 a casting method based on myType variable?

+5
source share
1 answer

Looking around, casting is not the right question to ask here. Here I just check the match. Dynamic casting would be useless since there is no way for the static analyzer to know what to do with it if it is cast based on the type of the variable.

+1
source

Source: https://habr.com/ru/post/1237114/


All Articles