【问题标题】:Using NSPredicate to filter on both Core attribute and entity使用 NSPredicate 过滤核心属性和实体
【发布时间】:2012-04-14 05:14:38
【问题描述】:

我在核心数据中有两个实体(称它们为 entityOne 和 entityTwo)。我在它们之间有一个 entityOne>entityTwo 关系。

我现在正在尝试编写一个 NSPredicate 以在以下基础上获取 entityTwo 对象:

  1. 获取 entityTwo 与指定 entityOne 对象有关系的对象。

  2. 过滤掉那些entityTwo对象,它们的属性之一没有值。

我最好在 NSPredicate 中同时执行这两项操作,还是有更好的方法?

我正在尝试以下方法:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(attribute <> "") AND (relationship == entityOne"];
    [request setPredicate:predicate];

任何关于编码的指针都已完全收到。

【问题讨论】:

    标签: iphone objective-c ios core-data nspredicate


    【解决方案1】:

    你可以像这样使用谓词:

    [NSPredicate predicateWithFormat:@"entityOneRelationship = %@ AND attribute.length > 0",specifiedEntityOne];
    

    很常见的方法。

    【讨论】:

    • 啊,这是我错了的字符串语法。您建议的代码检索属性设置为 nil 的实体。如何检索具有除 nil 以外的属性的实体?我已经尝试过!= 和 。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    相关资源
    最近更新 更多