You can't use AnyObject:
18> let ar : AnyObject?[] = [1, 2, nil, 4, 5]
<REPL>:18:25: error: cannot convert the expression's type 'AnyObject?[]' to type 'AnyObject?'
let ar : AnyObject?[] = [1, 2, nil, 4, 5]
^~~~~~~~~~~~~~~~~
But you can use Any:
18> let ar : Any?[] = [1, 2, nil, 4, 5]
ar: Any?[] = size=5 {
[0] = Some {
Some = <read memory from 0x7f8d4b841dc0 failed (0 of 8 bytes read)>
}
[1] = Some {
Some = <read memory from 0x7f8d50da03c0 failed (0 of 8 bytes read)>
}
[2] = Some {
Some = nil
}
[3] = Some {
Some = <read memory from 0x7f8d4be77160 failed (0 of 8 bytes read)>
}
[4] = Some {
Some = <read memory from 0x7f8d4be88480 failed (0 of 8 bytes read)>
}
}
The Apple documentation makes this clear:
“Swift provides two special type aliases for working with non-specific
types:
o AnyObject can represent an instance of any class type.
o Any can represent an instance of any type at all, apart from function types.”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.
https://itun.es/us/jEUH0.l
It appears that Int and probably other primitive types are not subtypes of a class type and thus AnyObject won't work.