core data - Convert NSArray to Swift Array<T> -
in coredata have defined ordered to-many relationship. relationship defined in swift this:
@nsmanaged var types : nsmutablearray however, use swift @ it's best, want use normal swift array type[]. however, coredata forces me use ns(mutable)array. how can type-cast / convert nsarray array<type>[]?
apparently confusion arises following error:
let array = obj.types t[] // cannot convert expression's type 'node[]' type '$t2' while accepted editor:
let array = obj.types anyobject[] t[] // no complaint
i'm using
obj.types.allobjects type[], feels hack/workaround.
then revise feelings. you're doing how do "type-cast / convert nsarray array<type>[]."
an nsarray arrives swift containing anyobject (i.e. array<anyobject>, aka anyobject[]). casting down specific type, if know contains 1 type, you, , how doing supposed do.
edit in swift 2.0 , new ios 9 apis, nsarray arrive correctly typed, , no cast needed.
edit 2 in swift 3.0, nsarray not correctly typed, though uncommon, arrive containing any instead of anyobject , still have cast down specific type.
Comments
Post a Comment