如果搜索字符串包含左“(”和右“)”括号,则 NSPredicate 不起作用

NSPredicate not working if search string contains left "(" and right ")" brackets

我正在使用 NSPredicate 从核心数据中搜索包含。 但是有些记录包含左右括号。 示例

产品名称 = "Product (Product1)" 我尝试按 prodcuctName 过滤数据,然后得到 0 个结果。

   self.productName = @"Product (Product1)";
   [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"productName MATCHES[cd] \"%@\"",self.productName]];

请建议我解决这个问题。

提前致谢!

我用 LIKE 替换了 MATCHES 关键字。

现在 NSPredicate 工作正常。 MATCHES 是根据 ICU v3 使用正则表达式样式比较的比较 left/right 表达式(有关详细信息,请参阅 Regular Expressions 的 ICU 用户指南)。

而LIKE只是比较等同于“==”。