如何设置NSPredicate以查找具有nil属性的对象 [英] How do I set up a NSPredicate to look for objects that have a nil attribute
本文介绍了如何设置NSPredicate以查找具有nil属性的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ManagedObject class
,该类的成员之一是NSDate
.我想显示未设置日期的类的所有对象.我尝试使用这样的谓词:
I have a ManagedObject class
, and one of the members of the class is a NSDate
. I would like to display all objects of the class for which the date is NOT set. I tried using a predicate like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(date = NIL)"];
但是我仍然得到设置了date
的对象.为此建立谓词的正确方法是什么?
But I still get objects where the date
is set. What is the right way to set up a predicate for this?
推荐答案
我认为这是区分大小写的问题.您可以使用"nil"或"NULL",但不能使用"NIL".这对我来说很好:
I think it's a case sensitivity issue. You can use "nil" or "NULL", but not "NIL". This works fine for me:
NSPredicate *eventWithNoEndDate = [NSPredicate predicateWithFormat:@"endDate = nil"];
这篇关于如何设置NSPredicate以查找具有nil属性的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文