【问题标题】:Core Data search second level objects (category of item)Core Data 搜索二级对象(项目类别)
【发布时间】:2011-10-20 18:34:07
【问题描述】:

我的核心数据系统使用具有单个类别集的项目(例如 item.category = <Category object>),我想使用我的 NSPredicate 来搜索它们。

目前发送搜索字符串“string”只会匹配包含该字符串的项目,但我也希望类别匹配。是否可以设置一个使用这种嵌套结构或自定义选择器的 NSPredicate 来告诉系统搜索字符串是否匹配?

在伪代码中,这是我正在寻找的:

if (item.title contains "search string" OR item.category.title contains "search string")
    object matches search string

【问题讨论】:

    标签: objective-c search core-data nspredicate


    【解决方案1】:

    是的,KVC(键值编码)允许您通过实体进行任意深度的链接。但是请注意,您加入的实体越多,谓词就越昂贵:

    [NSPredicate predicateWithFormat:@"title == %@ || category.title == %@", title, title];
    

    这是假设您针对“item”实体表运行谓词。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-25
      • 2016-09-17
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-05
      相关资源
      最近更新 更多