-2

When I set c to a

var a: [Any]
var c: Array<PostCategory>

error shown:

cannot convert value of type 'Array' to expected argument type [Any]

how to solve the problem?

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
leo_luck
  • 151
  • 2
  • 8
  • Where's the actual assignment taking place? – Alexander May 12 '16 at 13:38
  • 1
    Possible duplicate of [Why aren't \[SomeStruct\] convertible to \[Any\]?](http://stackoverflow.com/questions/37188580/why-arent-somestruct-convertible-to-any) – Hamish May 12 '16 at 15:29

2 Answers2

0

The error message is a bit misleading but try initializing the array before assigning it:

var c: Array<PostCategory> = []

...or...

var c = Array<PostCategory>()
Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
0

I bet your PostCategory is a struct. Apparently struct arrays aren't convertible to an Any array. This is weird because all types conforms to the Any protocol.

If you change the PostCategory to a class instead, it should work fine. You might need to create a new initializer for the class though, since classes doesn't give you the same default initializer as a struct does.

Laffen
  • 2,753
  • 17
  • 29