考虑代码:为什么Swift Array <Int>与AnyObject兼容?
struct S {
var f : Int64 = 0
}
...
let coder : NSCoder = someCoder ...
let a : [Int] = []
coder.encodeObject(a) // compiles
let b : [Int64] = []
coder.encodeObject(b) // doesn't compile: not AnyObject
let s : [S] = []
coder.encodeObject(s) // doesn't compile: not AnyObject
注意Int
被定义为struct
。
所以[Int]
是对象,但[Int64]
不是,也不是我的简单结构数组。
Int
的特别之处是什么?
只是为了保持完整性,还有什么其他种类型,其中在阵列中使用时,都将通过桥的NSArray? – rghome
符合'_ObjectiveCBridgeable'的任何内容。点击'Foundation'进入'Foundation'界面,然后搜索'_ObjectiveCBridgeable'。 –
有关文档,请参阅https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html#//apple_ref/doc/uid/TP40014216-CH6-ID61。 –