问题
i am implementing a core data example in xcode 4.2 at insertMethod (in MasterViewController.m class) my app crashes with a NSInternalInconsistencyException and error message: Context already has a coordinator; cannot replace. can any buddy tell me the meaning of this exception and error message
insert method given below:-
(void)insertNewObject
{
detailViewControllerObj = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
detailViewControllerObj.delegate = self;
NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
self.managedObjectContext = addingContext;
[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
detailViewControllerObj.cust = (Customer *) [NSEntityDescription insertNewObjectForEntityForName:@"Customer" inManagedObjectContext:addingContext];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewControllerObj];
[self.navigationController presentModalViewController:navController animated:YES];
}
and the app crashes after exectution of
[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
Any help will be more appreciable..
回答1:
this means that at the time of managedObjectContext's initialization, you have already binded it with the store. so you dont need to bind it again here so if you remove this line from your code, your code will work fine as the step you are trying to do has already been done at some prior stage.
来源:https://stackoverflow.com/questions/9223692/using-core-data-and-in-insertmethod-app-crashes-and-give-nsinternalinconsistency