Using Core Data and in insertMethod App crashes and give NSInternalInconsistencyException with error message Context already has a coordinator

非 Y 不嫁゛ 提交于 2020-01-23 02:35:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!