【问题标题】:NSPredicate to retrieve all objects whose attribute in an 1:n relationship is not NILNSPredicate 检索在 1:n 关系中属性不为 NIL 的所有对象
【发布时间】:2023-03-09 18:05:01
【问题描述】:

我想为 Core Data 查询 构建 NSPredicate,它应该检索所有 IBEstPeriod 托管对象,其 1:n 关系 estType.consHistory.consType NIL * .

不幸的是,我没有找到任何关于这样一个 NSPredicate 应该是什么样子的线索。您有什么想法或建议吗?

谢谢!

【问题讨论】:

    标签: objective-c ios core-data nspredicate


    【解决方案1】:

    对谓词中的多对关系使用“ANY”:

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:[NSEntityDescription entityForName:@"IBEstPeriod" inManagedObjectContext:context]];
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY estType.consHistory.consType != nil"]];
    
     NSArray *fetchResult = [managedObjectContext executeFetchRequest:fetchRequest error:nil];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 2011-08-10
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多