gpt4 book ai didi

iphone - NSPredicate 多字段搜索

转载 作者:可可西里 更新时间:2023-11-01 06:12:39 24 4
gpt4 key购买 nike

我正在尝试搜索多个字段。像这样:

[NSPredicate predicateWithFormat:@"(name title contains[cd] %@) AND (title contains[cd] %@",  self.searchBar.text];

在名称字段或标题字段上进行搜索。

此外,如果有人知道通配符搜索是什么样子,我也将不胜感激。

我试过:

 [NSPredicate predicateWithFormat:@"* contains[cd] %@",  self.searchBar.text];

我的错误代码:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(name contains[cd] %@) OR (title contains[cd] %@"'

最佳答案

首先,您必须指定要检查的所有属性,因为没有固定或通用的属性列表,并且在 Objective-C 中,属性与任何其他方法之间没有真正的语义区别。

其次,要检查多个属性以查看它们是否包含搜索字符串,您应该使用 OR,而不是 AND,因为如果 ,您的搜索就满足了任何属性匹配,而不是所有

否则,您的语法看起来是正确的(我假设第一个子谓词中的 name title 只是 name。)

关于iphone - NSPredicate 多字段搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6194225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com