检查coredata对象是否为nil

检查coredata对象是否为nil

问题描述:

我想找出核心数据中的对象,我的代码:

I want to find out the objects in the core data, my code:

类型:

signedDate (日期)

alarmDate (日期)

starTime (NSDate)

endTime (NSDate)

NSString *str = @"(signedDate >= %@) AND (signedDate < %@) AND (alarmDate == nil)";
NSPredicate *predicate = [NSPredicate predicateWithFormat:str, starTime, endTime];
[request setPredicate:predicate];
NSArray *results=[context executeFetchRequest:request error:nil];

谓词错了吗?
如何判断coredata对象为nil?
谓词应该是什么?

predicate is wrong ? How to judge an coredata object is nil? What the predicate should be?

我认为谓词语法不需要== nil。
仅使用一个=

I don't think the predicate syntax calls for == nil. Use only one =

NSString *str = @"(signedDate >= %@) AND (signedDate < %@) AND (alarmDate = nil)";

上面的代码可以正常工作。

Your code above works right. It should be YES since it's nil.

BOOL ok;
predicate = [NSPredicate predicateWithFormat:@"firstName = nil"];
ok = [predicate evaluateWithObject:[NSDictionary dictionary]];

ok = [predicate evaluateWithObject:
[NSDictionary dictionaryWithObject:[NSNull null] forKey:@"firstName"]];