Core Data NSFetchedResultsController: Error when debugging on device (Unable to generate SQL for predicate)
i have a weird exeption when i debug my app on my device. debugging in simulator works as expected.
- i use core data for storing my data
- relationships in model are as follows: Location <-> LocationDetails ->> HappyHour
- i use NSFetchedResultsController to populate a UITableView
- i'm also pretty new to objective-c develpoment
i need to have a SUBQUERY to get to the attributes of the HappyHour entity.
Like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(0 != SUBQUERY(details.%K, $hh, ($hh.startTime < %@) AND ($hh.endTime > %@)).@count)", weekdayString, theDate, theDate];
ONLY on the DEVICE i get this error/exeption:
* Terminating app due to uncaught exception 'NSInvalidArgu开发者_JAVA技巧mentException', reason: 'Unable to generate SQL for predicate (0 != SUBQUERY(details.hh_montag, $hh, $hh.startTime < CAST(316482000.000000, "NSDate") AND $hh.endTime > CAST(316482000.000000, "NSDate")).@count) (problem on RHS)'
0 CoreFoundation 0x32cf964f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3313cc5d objc_exception_throw + 24 2 CoreData 0x3228a829 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 688 3 CoreData 0x3228a2eb -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 378 4 CoreData 0x3228a169 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 16 5 CoreData 0x3228a005 -[NSSQLCore newRowsForFetchPlan:] + 288 6 CoreData 0x322892c5 -[NSSQLCore objectsForFetchRequest:inContext:] + 420 7 CoreData 0x32288875 -[NSSQLCore executeRequest:withContext:error:] + 304 8 CoreData 0x32287dd5 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 896 9 CoreData 0x3228669f -[NSManagedObjectContext executeFetchRequest:error:] + 374 10 CoreData 0x322b9d7f -[NSFetchedResultsController performFetch:] + 766 11 HappyHourRadar 0x0003e723 -[ResultViewController viewDidLoad] + 86 ... terminate called after throwing an instance of 'NSException' Signal received: SIGABRT (Aborted)Process finished with exit code -1
At [ResultViewController viewDidLoad] +86
i call
[self fetchedResultsController] performFetch:&error]
in the console i also get this message:
unable to load symbol file: unable to load symbol file: warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
As i haven't found anything that could help me, i guess it's either something really weird, or i just messed up something pretty standard, that i can't find because of my limited objective c background...
Anyway, i would be very glad if someone could give a hint, so i can continue without having to rewrite my entire application model layer to something dirty (like fetching all entries and holding them in an array and process filter functions...stuff like that ;) )
edit:
here is the model graph. from this auto-generated the model files.
Link to Image
generated HappyHour class:
@interface HappyHour : NSManagedObject
{
}
@property (nonatomic, retain) NSDate * endTime;
@property (nonatomic, retain) NSDate * startTime;
@end
i figured it out. Hopefully this will help someone, who is as blind, tired or whatever as myself. ;)
These bold marked passages clearly don't match:
- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to generate SQL for predicate (0 != SUBQUERY(details.hh_montag, $hh, $hh.startTime < CAST(316482000.000000, "NSDate") AND $hh.endTime > CAST(316482000.000000, "NSDate")).@count) (problem on RHS)'
and
@class Location;
@interface LocationDetails : NSManagedObject { }
@property (nonatomic, retain) NSString * phone;
...
@property (nonatomic, retain) NSSet * hh_monday;
...
@end
The final solution was:
NSTimeInterval secondsPerDay = 7 * 60 * 60;
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"EEEE"];
SOLUTION >> [f setLocale: [[[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"] autorelease]];
NSString *weekdayString = [NSString stringWithFormat:@"hh_%@", [[f stringFromDate:[NSDate dateWithTimeIntervalSinceNow:-secondsPerDay]] lowercaseString]];
Golden Rule:
Always keep in mind, that a device will work differently in a different location/language.
So, maybe avoid producing key selectors(?) from location/language-dependent classes like NSDate(Formatter).
Or make sure, that these classes return the same values for every case. (Hopefully something I have taken care of with this solution...correct me if I got that wrong.)
精彩评论