Why can't I cast `Woo<Any>` to `Woo<Int>` concrete type? But `Array<Any>` to `Array<Int>` is OK?

I went to sleep after that last post, and woke up thinking, "Wait, would that form possibly work for your actual use case?".

let array = [1,2,3]
let anyArray: [some Any] = array
let arrayActual = anyArray as! [Int] // πŸ˜ΆπŸ‘

struct Woo<Boo> { let boo: Boo }
let woo = Woo(boo: 3)
let anyWoo: Woo<some Any> = woo
let wooActual = anyWoo as! Woo<Int> // πŸ˜ΆπŸ‘
var xs2: [some Any] = [1, 2, 3]
xs2 as! [Int] // πŸ˜ΆπŸ‘
xs2.append("yello") // No exact matches in call to instance method 'append'

You still can't do as some though; you need the extra line.

2 Likes