我有一个使用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)
一切正常.
谁能解释这种行为?我很想弄清楚它是如何工作的.
提前感谢您提供的任何帮助......
克里斯