name <> myname
我觉得问这个问题有点愚蠢,但我在子查询中使用了上面的谓词。我期待看到名称不等于我的名字的所有行。但是,不返回名称为 NULL 值的行。这是正确的行为吗?
最佳答案
是的,这是意料之中的。参见 Null Values在《谓词编程指南》中:
A comparison predicate does not match any value with null except null (
nil
) or theNSNull
null value (that is, ($value == nil
) returnsYES
if$value
isnil
).
...
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/