In CoreData I have defined an ordered to-many relationship. This relationship is defined in Swift like this:
@NSManaged var types : NSMutableArray
let array = obj.types as T // Cannot convert expression's type 'Node' to type '$T2'
let array = obj.types as AnyObject as T // No complaint
I'm currently using
obj.types.allObjects as Type, but that feels like a hack/workaround.
Then revise your feelings. What you're doing is exactly how you do "type-cast / convert the
An NSArray always arrives into Swift as containing
AnyObject (i.e. an
AnyObject). Casting it down to a specific type, if you know that it contains all one type, is up to you, and how you are doing it is exactly what you are supposed to do.
EDIT In Swift 2.0 and the new iOS 9 APIs, an NSArray will often arrive correctly typed, and no cast will be needed.