Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有无效谓词的核心数据崩溃:nil RHS_Ios_Objective C_Core Data - Fatal编程技术网

Ios 具有无效谓词的核心数据崩溃:nil RHS

Ios 具有无效谓词的核心数据崩溃:nil RHS,ios,objective-c,core-data,Ios,Objective C,Core Data,我在执行fetch请求时发生了此崩溃,但从崩溃报告中可以清楚地看出,崩溃的原因是谓词为nil。我已经为起始日期为零的情况添加了一张支票。我应该注意的无效谓词是否还有其他潜在原因 NSFetchRequest *calRequest = [NSFetchRequest fetchRequestWithEntityName:@"Calendar"]; calRequest.predicate = [NSPredicate predicateWithFormat:@"date >= %@", s

我在执行fetch请求时发生了此崩溃,但从崩溃报告中可以清楚地看出,崩溃的原因是谓词为nil。我已经为起始日期为零的情况添加了一张支票。我应该注意的无效谓词是否还有其他潜在原因

NSFetchRequest *calRequest = [NSFetchRequest fetchRequestWithEntityName:@"Calendar"];
calRequest.predicate = [NSPredicate predicateWithFormat:@"date >= %@", startDate];
calRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]];
NSError *error = nil;
NSArray *results = [appDelegate.managedObjectContext executeFetchRequest:calRequest error:&error];
事故报告

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x30534f03 __exceptionPreprocess + 130
1  libobjc.A.dylib                0x3acc9ce7 objc_exception_throw + 38
2  CoreData                       0x30289f17 -[NSComparisonPredicate(_NSCoreDataSQLPredicateCategories) minimalFormInContext:] + 926
3  CoreData                       0x3028952b -[NSSQLGenerator initializeContextForFetchRequest:ignoreInheritance:nestingLevel:] + 538
4  CoreData                       0x30288f9f -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 34
5  CoreData                       0x30288e3f -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 406
6  CoreData                       0x30288aa3 -[NSSQLCore newRowsForFetchPlan:] + 114
7  CoreData                       0x302881e7 -[NSSQLCore objectsForFetchRequest:inContext:] + 698
8  CoreData                       0x30287c8b -[NSSQLCore executeRequest:withContext:error:] + 446
9  CoreData                       0x30287539 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 2892
10 CoreData                       0x3028593b -[NSManagedObjectContext executeFetchRequest:error:] + 614
11 MyApp                           0x0010b769 -[Calendar calendarLoad] (Calendar.m:152)
...

在创建谓词之前,是否尝试记录
startDate
的值?这个错误听起来几乎肯定会是nil…我认为我的问题是设置startDate的方式,这有时会导致nil谓词。我现在正在记录startDate值,但崩溃是非常随机的。我只是想确定没有其他可能的原因。如果使用NSDateFormatter解析开始日期,则默认设置需要严格匹配,这将导致返回零。如果这是问题所在,请尝试将lenient设置为true。使用相同的设置。我几乎没有属性,总是只查询一个对象。但只有在查询其中一个属性时,才会出现此错误。马丁,你解决了吗?