I am trying to save a managed object with one of the attributes of type Date in managedObjectContext .
The code is similar:
reminder.eventDate = selectedDate; NSLog(@"Date: %@", selectedDate); NSError *error = nil; if (![reminder.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); }
during an emergency stop of a program with SIGABRT. Here is the console log:
2011-02-28 00: 50: 18.817 MyApp [9021: 207] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '- [__ NSDate isEqualToString:]:
unrecognized selector sent to instance 0x4e73490 '
*** Call stack at first throw:
(
0 CoreFoundation 0x01057be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x011ac5c2 objc_exception_throw + 47
2 CoreFoundation 0x010596fb - [NSObject (NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00fc9366 ___forwarding___ + 966
4 CoreFoundation 0x00fc8f22 _CF_forwarding_prep_0 + 50
Does anyone know why I have this? The second question is why, when I check the debug mode of selectedDate , it is not an NSDate type, but __NSDate (double underscore in front).
Thanks!
UPDATE:
I made some changes to make it easier to catch a mistake. so the code is now similar:
reminder.eventDate = [NSDate date]; NSLog(@"Date: %@", selectedDate); NSError *error = nil; if (![reminder.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); }
So here we are exactly saving the NSDate. reminder.eventDate is also an NSDate. But I still have this error. If I comment on reminder.eventDate = [NSDate date]; save, then another error (date is a required field in NSData, so save: returns the error "Operation could not be completed") using eventDate = nil; . The CoreData structure is checked several times - eventDate has a date type.
UPDATE (problem resolved): I finally found the problem. eventDate was set as the key for detailTextLabel.text in my tableview cells (I used KVO for this). So if there wasn’t a direct call, and I couldn’t find any invokation method for eventDate . The strange thing is that the accident was by the save method, and not later. And in the call stack there is no tableView:cellForRowAtIndexPath: method tableView:cellForRowAtIndexPath: in general ...
ios objective-c iphone core-data
Ogreswamp
source share