I'm having some issues with saving a new object/editing an existing one, from a One-To-Many relationship in CoreData.
I have a class Patient that has a To-Many relationship with class Indication.
What's been happening is: First time I create an Indication Object from a normal workflow, it all seems to save alright, but if I try to access it from an Edit screen, it crashes with a SIGABRT and the following error
-[Patient compare:]: unrecognized selector sent to instance 0x7fa991893ca0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Patient compare:]: unrecognized selector sent to instance 0x7fa991893ca0'
The same happens if I try to create a new one from the NSFetchedResultsController that shows the list of Indication Objects.
I've tried to create the relationships between them in two ways:
indication = [NSEntityDescription insertNewObjectForEntityForName:@"Indication"
inManagedObjectContext:appDelegate.managedObjectContext];
indication.patient = patient;
and through the GeneratedAccessors from CoreData:
[patient addIndicationObject:indication];
and I validate both objects during viewDidLoad to avoid creating a new Indication if I'm editing an existing one. But in both cases I get the same error.
Haven't been able to find any posts related to this matter so far. Please help.
After a few days researching this with no success, finally I've managed to find a post that managed to shine some light on the problem.
It happens that the NSFetchedResultsControllerDelegate seems to "lock" the NSManagedObjectContext and that's why I couldn't add or change anything within the same context.
I just had to set the delegate to nil once I left the screen and everything seems to work just fine now.
Thanks for the solution on this post: Core data: Serious application error
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.