I’ve always been wondering how Swift’s [Any]
arrays work internally. E.g.
struct Dog {
let name: String
let age: Int
}
struct Foo {
let a: String
let b: Int
let c: Int
}
func test() -> [Any] {
let s = [Dog(name: "James", age: 23), Foo(a: "abc", b: 2, c: 2)] as [Any]
return s
}
print(test()[0])
Does Swift simply allocate an array of pointers and copy the structs into the heap? Or is there some other kind of magic going on? Does it bridge the array to NSArray?