Convert NSArray to Swift Array

后端 未结 4 1690
终归单人心
终归单人心 2020-12-29 03:23

In CoreData I have defined an ordered to-many relationship. This relationship is defined in Swift like this:

@NSManaged var types : NSMutableArray
<         


        
4条回答
  •  温柔的废话
    2020-12-29 04:09

    You are going to have to create a new generic array and manually populate it as follows:

        var result = Type[]()
    
        for item : AnyObject in self {
            //  Keep only objC objects compatible with OutType
            if let converted = bridgeFromObjectiveC(item, Type.self) {
                result.append(converted)
            }
        }
    

提交回复
热议问题