【发布时间】:2012-06-01 12:22:37
【问题描述】:
抱歉,如果这是重复的,20 分钟的搜索没有得出这种确切的情况或解决方案。
我有一个核心数据堆栈,其中包含三个类 XClass、YClass 和 ZClass。 XClass 与 YClass 具有一对多的关系。 YClass 与 ZClass 是一对多的关系。
使用NSFetchedResultsController 的实例,我试图获取至少有1 个YClass 至少有1 个ZClass 的XClass 的所有实例。
我的谓词定义如下:
// ...stuff
NSFetchRequest * fetchRequest = [NSFetchRequest new];
NSEntityDescription * entity = [NSEntityDescription entityForName:NSStringFromClass([XClass class])
inManagedObjectContext:managedObjectContext];
fetchRequest.entity = entity;
fetchRequest.predicate =
[NSPredicate predicateWithFormat:@"0 < SUBQUERY(yObjects, $y, $y.zObjects.@count > 0).@count"];
// ..instantiate NSFetchedResultsController and perform fetch
这会导致消息出现致命异常:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Keypath containing KVC aggregate where there shouldn't be one; failed to handle $y.zObjects.@count'
在其他地方,我使用谓词 [NSPredicate predicateWithFormat:@"zObjects.@count > 0"]; 成功获取了 YObject 实例
有人可以指出我做错了什么吗?非常感谢。
【问题讨论】: