ios - 核心数据不等于谓词

标签 ios core-data

name <> myname

我觉得问这个问题有点愚蠢,但我在子查询中使用了上面的谓词。我期待看到名称不等于我的名字的所有行。但是,不返回名称为 NULL 值的行。这是正确的行为吗?

最佳答案

是的,这是意料之中的。参见 Null Values在《谓词编程指南》中:

A comparison predicate does not match any value with null except null (nil) or the NSNull null value (that is, ($value == nil) returns YES if $value is nil).
...
If you want to match null values, you must include a specific test in addition to other comparisons, ...

这意味着两者 "name = myname""name <> myname"如果 name 则评估为否 为空。

您可以将谓词更改为

name <> myname OR name = NULL

涵盖这两种情况。

关于ios - 核心数据不等于谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23415163/

相关文章:

javascript - 在我的 iOS 应用程序中集成 jquery-javascript 项目

iphone - 达到 NSDictionary 中最深的子级别

ios - 具有正偏移量的 CenterXAnchor 不起作用?

ios - CoreData 获取实体

ios - CoreData NSOrderedSet-修复吗?

iphone - 在我的屏幕上安装 iPhone 5 模拟器?

ios - 允许在使用 iOS Google Maps SDK 设置方位动画时捏合缩放

ios - 核心数据 : How to pass a managed object to a UITableViewCell and do a fetchRequest from there?

cocoa - iPhone核心数据关系故障

iphone - 由于libdispatch-manager而崩溃