coredata如何将默认NSSet更改为NSMutableArray [英] coredata how to change default NSSet to NSMutableArray
问题描述
CoreData一对多默认生成 NSSet
,如何更改 NSSet
为 NSMutableArray
?我尝试手动更改,但得到错误:
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'
推荐答案
NSSet
具有 allObjects
的方法,它返回 NSArray
。
NSSet
has the method allObjects
, which returns an NSArray
.
要获得 NSMutableArray
,您可以这样做:
To get an NSMutableArray
you could do this:
NSMutableArray *array = [NSMutableArray arrayWithArray:myCoreDataObject.mySet.allObjects];
注意:订单不能保证每次都一样如果命令对您很重要,请考虑使用 NSOrderedSet
。
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.
另请参阅 NSSet
:
PS:
出现错误的原因:
NSSet
(或 _NSFaultingMutableSet
)没有一个方法 filteredArrayUsingPredicate
。
NSSet
(or _NSFaultingMutableSet
for that matter) doesn't have a method called filteredArrayUsingPredicate
.
这篇关于coredata如何将默认NSSet更改为NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!