Your var students is a Swift array and expects an object of type AnyObject , but you try assigning it an NSArray . Two objects are not of the same type, and they do not work.
But, given that NSArray compatible with [AnyObject] , you can use simple casts to make NSArray into a Swift array:
school.students = studentArray as [AnyObject]
Of course, the best approach would be to stay in the Swift world and forget about NSArray altogether, making getAllStudents return a Swift array instead of an NSArray. Not only will you not have to do type tricks, but you can also take advantage of Swift collections.
source share