I have an enum and I\'d like to create a method to return a different type for every case.
For example, I have a dictionary [String: Any]
. To process the va
I think the core of the problem here is that Swift has strict typing. That means types must be known at compile time. This, obviously, is legal:
let s : Any = "howdy"
if let ss = s as? String {
print(ss)
}
But this is not legal:
let s : Any = "howdy"
let someType = String.self
if let ss = s as? someType { // *
print(ss)
}
someType
must be a type; it cannot be a variable hiding a type inside itself. But that is precisely what, in effect, you are asking to do.