核心数据 - NSPredicate可过滤多对多关系

ind*_*gie 9 iphone cocoa-touch core-data nspredicate nsfetchrequest

我有2个实体,任务和列表.每个任务与一个名为"list"的List对象具有一对一的关系,并且与List有一个反向关系,它与Task有一个to-many关系,称为"tasks".

我正在尝试使用带有NSPredicate的获取请求来获取属于指定List的所有Task对象:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"list=%@", theList];
[fetchRequest setPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

(其中"theParent"是对List对象的引用).但是,这不会返回任何提取的对象.如果我取出谓词,那么返回对象(所以我知道它们存在,并且通过NSLogging theList我知道它有与之关联的Task对象).

谢谢

kha*_*son 11

这可能是你谓词中的一个简单错字吗?

当我假设你真正想要的是"list ==%@"时,你有"list =%@"

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"list == %@", theList];
[fetchRequest setPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

  • kharrison和/或@sza:你能澄清一下你的意思吗?[该NSPredicate文档】(https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-215832)声称`=在谓词格式字符串中使用时,`和`==`是100%等效的.是否有无证件的差异? (4认同)
  • "="适用于财产,但不适用于关系. (3认同)