I have this failure while executing a query for sampling, but it is clear from the failure report that the reason for the failure is that the predicate is zero. I added a check for the case when startDate is zero. Is there any other potential reason for the wrong predicate that I have to take care of?
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];
Crash report
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)
...
source
share