NSPredicate 字符串与 NSSet 匹配
我正在尝试使用 NSPredicate 来搜索与生成的 CoreData 对象数组相匹配的字符串,如下所示:
// Grab an array of all Company projects
NSArray *array = [[company projects] allObjects];
我使用以下谓词将任何项目名称、公司名称或客户名称与不区分大小写的字符串匹配(注意:这应该允许部分匹配,以便“App”将匹配“Apple Inc.”等):
(name LIKE[cd] %@) OR (ANY companies.name LIKE[cd] %@) OR (ANY companies.clients.name LIKE[cd] %@)
谓词中提到的 CoreData 关系如下所示:
SELF -> (NSString *) name
SELF -> (NSSet *) companies -> (NSString *) name
SELF -> (NSSet *) companies -> (NSSet *) -> clients -> (NSString *) name
每当我尝试按上述谓词进行过滤时,我都会在控制台中找到以下内容:
HIToolbox: ignoring exception 'Can't do regex matching on object {(
"Apple Inc.",
"Test Co.",
Microsoft
)}.'
如果我理解正确的话,看起来好像尝试匹配键路径“companies.clients.name”会返回一个 NSSet (或其他对象),其中需要 NSString (名称)。
我做错了什么?
I'm trying to use an NSPredicate to search for string matches against an array of CoreData objects generated like so:
// Grab an array of all Company projects
NSArray *array = [[company projects] allObjects];
I use the following predicate to match any project names, company names or client names with a case-insensitive string (note: this should allow for partial matches, so that 'App' will match 'Apple Inc.', etc):
(name LIKE[cd] %@) OR (ANY companies.name LIKE[cd] %@) OR (ANY companies.clients.name LIKE[cd] %@)
The CoreData relationships mentioned in the predicate look like so:
SELF -> (NSString *) name
SELF -> (NSSet *) companies -> (NSString *) name
SELF -> (NSSet *) companies -> (NSSet *) -> clients -> (NSString *) name
Whenever I attempt to filter by the above predicate, I find the following in my Console:
HIToolbox: ignoring exception 'Can't do regex matching on object {(
"Apple Inc.",
"Test Co.",
Microsoft
)}.'
If I'm understanding things correctly, it looks as though trying to match against the keypath "companies.clients.name" returns an NSSet (or other object) where an NSString (name) was expected.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
companies.clients.name
将返回NSSet
的集合,其中集合中的每个元素都是一个公司的客户名称的内容(即一个NSSet
>)。您可能想要使用[电子邮件受保护]
在你的谓词字符串中。请参阅使用指南 键值编码中的集合和数组运算符。
companies.clients.name
will return collection ofNSSet
s, where each element in the colletion is the contents of one companie's client's names (i.e. anNSSet
). You probably want to use[email protected]
in your predicate string.See the guide on using Set and Array Operators in Key-Value Coding.