NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES[cd] %@ AND (NOT (SELF MATCHES[cd] %@))", [NSString stringWithFormat: @".*\\b%@.*", string],[NSString stringWithFormat: @".*\\[\\b%@.*", string]];
我的代码有什么问题?
答案 0 :(得分:0)
尝试使用子查询功能,这对你有帮助
[NSPredicate predicateWithFormat@"(add == %@) AND (SUBQUERY(subs, $x, $x.numbervalue == %@ or $x.numbervalue == %@).@count > 0)", @"add",number1, number2];
另:
AND& OR可以在谓词格式字符串中使用,以创建复合predicates
。但是,使用NSCompoundPredicate
可以实现同样的目的。
例如,以下谓词是等效的:
[NSCompoundPredicate andPredicateWithSubpredicates:@[[NSPredicate predicateWithFormat:@"age > 25"], [NSPredicate predicateWithFormat:@"firstName = %@", @"Raja"]]];
[NSPredicate predicateWithFormat:@"(age > 25) AND (firstName = %@)", @"Raja"];
来源: Mattt Thompson