coredata如何将默认NSSet更改为NSMutableArray [英] coredata how to change default NSSet to NSMutableArray

查看:272
本文介绍了coredata如何将默认NSSet更改为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

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

PS:

出现错误的原因:

NSSet (或 _NSFaultingMutableSet )没有一个方法 filteredArrayUsingPredicate

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

这篇关于coredata如何将默认NSSet更改为NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆