小编Chr*_* T.的帖子

核心数据/可可:@distinctUnionOfObjects没有返回可用的NSArray*

我有一个使用Core Data的应用程序,它具有我想要分组的关系.我有我的.xcdatamodel文件生成的NSManagedObject类,并且大部分内容似乎都正常.

鉴于父/子关系,我想做以下事情:

父母有一个孩子的集合.孩子们有一个属性,groupByProperty,我想分组.

以下代码:

NSSet *allChildren = parent.children;
NSArray *groups = [allChildren valueForKeyPath:@"@distinctUnionOfObjects.groupByProperty"];
Child *child = [groups objectAtIndex:x]; //x is the row that I would like to retrieve
Run Code Online (Sandbox Code Playgroud)

尝试设置子指针时产生NSInvalidArgumentException.

但是,当我这样做时:

NSSet *allChildren = parent.children;
NSArray *groups = [[NSArray alloc] initWithArray:[allChildren valueForKeyPath:@"@distinctUnionOfObjects.groupByProperty"]];
Child *child = [groups objectAtIndex:x]; //x is the row that I would like to retrieve
Run Code Online (Sandbox Code Playgroud)

一切正常.

谁能解释这种行为?我很想弄清楚它是如何工作的.

提前感谢您提供的任何帮助......

克里斯

iphone cocoa cocoa-touch core-data objective-c

4
推荐指数
1
解决办法
4646
查看次数

标签 统计

cocoa ×1

cocoa-touch ×1

core-data ×1

iphone ×1

objective-c ×1