I have tried the following code, I can cast to Array as the type parameter.
let x: Array = [21,43,12]
let z: Any = x
if let arr = x as? Array<Any>{
print("yes") // print "yes"
}
but why the following code doesn't work at all:
struct Base<T>{
let val: T
init(_ val: T){
self.val = val
}
}
let y = Base(7)
let an: Any = y
if let temp = an as? Base<Any> {
print("yes") // the line won't print.
}
is it a bug?
and is it possible to do like that:
let arr = [232,32,55]
let x: Any = arr
if x is Array { // error.
print("yes") // won't work. is any way to make it work?
}