coredata how to change default NSSet to NSMutableArray

时光毁灭记忆、已成空白 提交于 2020-01-03 20:41:16

问题


CoreData one-to-many default to generate NSSet ,how to change NSSet to NSMutableArray?I try to change it manually,but get error:

 _NSFaultingMutableSet filteredArrayUsingPredicate:]: unrecognized selector sent to instance 0x1ed35e40'

回答1:


NSSet has the method allObjects, which returns an NSArray.

To get an NSMutableArray you could do this:

NSMutableArray *array = [NSMutableArray arrayWithArray:myCoreDataObject.mySet.allObjects];

Note: order is not guaranteed to be the same every time (sets aren't ordered). If order is important to you, consider an NSOrderedSet instead.

See also the docs on NSSet:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSSet_Class/Reference/Reference.html

PS:

The reason you're getting said error:

NSSet (or _NSFaultingMutableSet for that matter) doesn't have a method called filteredArrayUsingPredicate.



来源:https://stackoverflow.com/questions/14617194/coredata-how-to-change-default-nsset-to-nsmutablearray

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!