1

我一直在环顾四周,看到了与我正在做的类似但无法让它们工作的例子。我有一个“产品”核心数据实体,它与“制造商”实体有一对多关系。“制造商”有一个我要搜索的属性“名称”。“产品”还有一个我希望搜索的“isCustomItem”属性。所以我想要达到的效果如下:

Product1...mManufacturer.nameProduct.isCustomItem== 0

到目前为止,这是我设法聚在一起的:

NSPredicate *p3 = [NSPredicate predicateWithFormat:@"SUBQUERY(manufacturer,$m,$m.name CONTAINS[c] %@) AND (isCustomItem == 0)", searchString];

但是我不断收到错误消息:

**'Unable to parse the format string "SUBQUERY(manufacturer,$m,$m.name CONTAINS[c] %@) AND (isCustomItem == 0)"'**
4

1 回答 1

4

尝试这样的事情......

NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"ANY manufacturer.name CONTAINS[c] %@", searchString];
NSPredicate *customPredicate = [NSPredicate predicateWithFormat:@"isCustomItem == 0"];

NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubPredicates:@[namePredicate, customPredicate]];

然后使用 CompoundPredicate 过滤您的集合。

于 2013-04-03T09:10:23.960 回答