
鉴于父/子关系,我想做以下事情:
父母有一个孩子的集合.孩子们有一个属性,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
尝试设置子指针时产生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
一切正常.
谁能解释这种行为?我很想弄清楚它是如何工作的.
提前感谢您提供的任何帮助……
克里斯
解决方法 所以,我从这个Apple文档得到了我的信息: Set and Array Operators,其中声明“@distinctUnionOfObjects运算符返回一个数组,其中包含通过发送valueForKeyPath:返回到接收器中每个项目返回的不同对象,将键路径传递到数组的右侧 *** 作符“.我假设返回的对象是一个NSArray,因为它说“Array”,它应该说“Array或Set”.我将返回的Object更改为NSSet,然后使用[[groups allObjects] objectAtIndex:x]将我的对象从那里取出.它现在看起来像这样:
NSSet *allChildren = parent.children;NSSet *groups = [allChildren valueForKeyPath:@"@distinctUnionOfObjects.groupByProperty"];Child *child = [[groups allObjects] objectAtIndex:x]; //x is the row that I would like to retrIEve
感谢您的帮助,我想我只需要更仔细地查看异常,这里的关键是“ – [NSCFSet objectAtIndex:…..”
总结以上是内存溢出为你收集整理的iphone – Core Data / Cocoa:@distinctUnionOfObjects没有返回可用的NSArray *全部内容,希望文章能够帮你解决iphone – Core Data / Cocoa:@distinctUnionOfObjects没有返回可用的NSArray *所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)