NSPredicate 连接属性
我正在尝试弄清楚如何连接属性名称。我有一个县和一个地区属性,我想要查询,就像
[NSPredicate predicateWithFormat:@"county + district contains[cd] %@",searchBar.text]
给我未实现的 SQL 生成谓词错误一样。我不知道如何实现 NSPredicate。 谢谢
I m trying to figure out how to concatenate attribute names. I have a county and a district attribute that I want to query like
[NSPredicate predicateWithFormat:@"county + district contains[cd] %@",searchBar.text]
gives me unimplemented SQL generation for predicate error. and I am not sure how to implement NSPredicate.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该会让您了解如何进行一些更复杂的搜索。它将匹配“县区”、“县区”等查询。
请参阅 Cocoa 是我的女朋友:向您的 Core Data 应用程序添加 iTunes 式搜索以获取更多说明。
This should give you an idea of how to do some more complicated searching. It will match queries for "county district", "district county", etc.
See Cocoa Is My Girlfriend: Adding iTunes-style search to your Core Data application for more explanation.
我最终实现了另一个字段作为连接两个变量(地区+国家)并对该变量执行查询。
I ended up implementing another field as concatenating the two variables(district+country) and perform the query on that variable.
我做了类似的事情并得出结论,像 cekisakurek 一样,最好的方法是将字段连接到一个公共字段(与名字/姓氏更相关)
,然后使用“contains[cd]”过滤该字段
I did something similar and concluded that like cekisakurek, the best method was to concatenate the fields into a common field (more relevant for first/last name)
and then filtered on this field using 'contains[cd]'
只需尝试上面的代码行,它会对您有所帮助。
Just try the above lines of code, it would helps you.