1
 var array = [AnyObject]()
 struct Test {}
 array.append(Test())

When I write this code in the play ground it gives me the following error Type 'Test' does not conform to protocol 'AnyObject'

I am guessing it is failing because struct is a value type not a reference type. But when I run this code

var array = [AnyObject]()
array.append(1)
array.append(2.0)
array.append("3")

It works but these are all also value types but in this case no error is given Why?

4

1 回答 1

0

对于您的成功案例,幕后正在进行一些转换。

尝试在追加的末尾添加它以查看发生了什么:

for item in array {
    print(item.dynamicType)
}
于 2016-05-31T13:04:05.797 回答