gpt4 book ai didi

ios - 检查 coredata 对象是否为 nil

转载 作者:技术小花猫 更新时间:2023-10-29 10:14:05 27 4
gpt4 key购买 nike

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

类型:

signedDate(日期)

alarmDate(日期)

starTime(NSDate)

结束时间(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?谓词应该是什么?

最佳答案

我不认为谓词语法要求 == nil。只用一个 =

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

您上面的代码工作正常。它应该是 YES,因为它是零。

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

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

关于ios - 检查 coredata 对象是否为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10245958/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com