【问题标题】:Setting predicate to search in Core Data在 Core Data 中设置要搜索的谓词
【发布时间】:2011-01-17 19:24:45
【问题描述】:

我需要在我的 iPhone 应用中搜索核心数据实体。

在我的核心数据中,我有一个实体“myEntity”,它有两个属性“stringOne”和“stringTwo”;都定义为 NSString。

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringOne contains[cd] %@", self.keyword4Search]; 
[fetchRequest setPredicate:predicate];

我上面的代码仅在 stringOne 中搜索包含 keyword4Search 的实体。

我需要的是在[stringOne OR stringTwo]中搜索包含keyword4Search的实体。


我希望有种

predicateWithFormat:@"stringOne or stringTwo contains[cd] %@", self.keyword4Search];

我应该去哪里看?

【问题讨论】:

    标签: iphone core-data predicate


    【解决方案1】:
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringOne contains[cd] %@ OR stringTwo contains[cd] %@", self.keyword4Search, self.keyword4Search];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-04
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-23
      • 1970-01-01
      相关资源
      最近更新 更多