Alexander Alexander - 1 year ago 40
Swift Question

Type Casting For AnyObject to represent instances of any reference type

var array = [AnyObject]()
struct 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]()

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


For your success case, there is some conversion going on behind the scenes.

Try adding this at the end of your appends to see what's happening:

for item in array {