核心数据搜索二级对象(项目类别)
我的核心数据系统使用具有单个类别集的项目(例如 item.category =
),并且我想使用 NSPredicate 来搜索它们。
目前发送搜索字符串“string”将仅匹配包含该字符串的项目,但我希望类别也匹配。是否可以设置一个使用此嵌套结构或自定义选择器的 NSPredicate 来告诉系统搜索字符串是否匹配?
在伪代码中,这就是我正在寻找的内容:
if (item.title contains "search string" OR item.category.title contains "search string")
object matches search string
My core data system uses items that have a single category set (for example item.category = <Category object>
) and I want to use my NSPredicate to search through them.
Currently sending a search string "string" will only match items that contain that string, but I want categories to match as well. Is it possible to set up an NSPredicate that uses this nested structure or a custom selector to tell the system if the search string matches?
In pseudo-code, here is what I'm looking for:
if (item.title contains "search string" OR item.category.title contains "search string")
object matches search string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,KVC(键值编码)允许您通过实体进行任意深度的链接。但是请注意,连接在一起的实体越多,谓词的成本就越高:
这是假设您正在针对“item”实体表运行谓词。
Yes, KVC (Key Value Coding) allows you to chain as deep as you want through entities. However be warned that the predicate gets more expensive the more entities you join together:
This is assuming you are running the predicate against the "item" entity table.