ios 6 core data "CoreData: error: Serious application error."

core-data, ios, ios6

Solution

You may want to try removing the `ANY` from the predicate, if Incident can only have zero or one parent relationship. This is the code:

[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"relationship == %@", self.parentRelationship]];

Problem

Ok, This is my first post to stackoverflow ever. I have been banging my head against the wall on this for hours upon hours. I hate typing out questions; you can trust I've exhaustively tried to figure this out on my own. I have done some research on the following error, however I am still unable to solve it. That being said, I am a noob ios 6 developer, and have a problem with core data. The error is: "CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet. with userInfo (null)" Now, my data model is the following: I have two entities (a one to many relationship). The relationship is behavior -> incident, where there are 0 to an unbound number of occurrences of incidents. What I do is this; In the behaviors table view controller, I populate an NSFetchedResultsController like the following: ``` - (NSFetchedResultsController *)fetchedResultsController { NSLog(@"Started Fetching In Behaviors..."); if (fetchedResultsController != nil) { return fetchedResultsController; } AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; NSManagedObjectContext *context = [appDelegate managedObjectContext]; NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Behavior" inManagedObjectContext:context]; [fetchRequest setEntity:entityDesc]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; aFetchedResultsController.delegate = self; self.fetchedResultsController = aFetchedResultsController; return fetchedResultsController; } ``` All of this works fine and hunky dory. The table gets populated with no problems. Now, what I do when a cell is selected, I instantiate another UITableViewCell controller, ``` { NSLog(@"A value was selected from the table view"); IncidentsViewController *vc = [[IncidentsViewController alloc] initWithStyle:UITableViewStylePlain]; vc.managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; vc.parentRelationship = [self.fetchedResultsController objectAtIndexPath:indexPath]; NSLog(@"Managed set on Incidents View Controller: %@", vc.managedObject); NSString* name = [[NSString alloc] initWithString:[[vc.managedObject valueForKey:@"name"] description]]; NSLog(@"Name of selected object: %@", name); [self.navigationController pushViewController:vc animated:YES]; } ``` The next IncidentsViewController from above has basically the exact same fetchedResultsController. I will paste it for completeness. ``` - (NSFetchedResultsController *)fetchedResultsController2 { NSLog(@"Started Fetching Resuts from Incidents View Controller..."); if (fetchedResultsController2 != nil) { NSLog(@"fetchedResultsController not null"); return fetchedResultsController2; } AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; NSManagedObjectContext *context = [appDelegate managedObjectContext]; NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Incident" inManagedObjectContext:context]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:entityDesc]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"when" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSLog(@"parent relationship: %@", self.parentRelationship); NSLog(@"managed object: %@", self.managedObject); [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY relationship == %@", self.parentRelationship]]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; aFetchedResultsController.delegate = self; self.fetchedResultsController2 = aFetchedResultsController; /* self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; self.fetchedResultsController.delegate = self; */ NSLog(@"Ending fetching results from incidents controller..."); return fetchedResultsController2; } ``` My problem is simply the following: When I have the line ``` [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY relationship == %@", self.parentRelationship]]; ``` In the second view controller, everything gets populated in to the table properly (i.e. only incidents for the particular Behavior that were selected appear in the list. if this line is present, and I try to add a new record to the Incidents entity, the error above is thrown. If I remove this particular line, every single behavior appears in the list (which is to be expected). However, When I try to add something to the incidents table, that the error is actually being thrown in the BehaivorViewController; this is very surprising to me, because I instantiated new NSFetchedResultsController, AppDelegate, and NSManagedObjectContext that are specifically local to each respective view controller. It seems to me like these two are interconnected some how, although I can't seem to figure out how. Would it be possible for somebody who knows a little bit about core data to chime in on this. I've posted my complete project to the following URL: https://webshare.uchicago.edu/users/dansully/Public/Dirty.zip The line in question is line 310 in IncidentsViewController.m. Thank-you so very much for helping me answer my question. I am going to continue working on this, I will report back if I find a solution.

Original source