我一直在环顾四周,看到了与我正在做的类似的例子,但无法让它们工作。我有一个"Product“核心数据实体,它与一个"Manufacturer”实体有多对多的关系。“制造商”有一个我想要搜索的属性"name“。“产品”也有一个属性"isCustomItem“,我也希望搜索它。所以我想要达到的东西是这样的:
Product 1...m Manufacturer.name和Product.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)"'**发布于 2013-04-03 17:10:24
试试这样的..。
NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"ANY manufacturer.name CONTAINS[c] %@", searchString];
NSPredicate *customPredicate = [NSPredicate predicateWithFormat:@"isCustomItem == 0"];
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubPredicates:@[namePredicate, customPredicate]];然后使用compoundPredicate过滤你的集合。
https://stackoverflow.com/questions/15782986
复制相似问题