"Collection was mutated while being enumerated" on executeFetchRequest "Collection was mutated while being enumerated" on executeFetchRequest multithreading multithreading

"Collection was mutated while being enumerated" on executeFetchRequest


OK, I think I've solved my problem and I must thank this blog post from Fred McCann's :

http://www.duckrowing.com/2010/03/11/using-core-data-on-multiple-threads/

The problem seems to come from the fact that I instantiate my background moc on the main thread instead of the background thread. When Apple tells that each thread needs to have its own moc, you have to take it seriously : each moc must be instantiated in the thread that will be using it !

Moving the following lines...

// We instantiate the background mocself.backgroundMOC = [[[NSManagedObjectContext alloc] init] autorelease];[self.backgroundMOC setPersistentStoreCoordinator:[self.managedObjectContext persistentStoreCoordinator]];

...in the _importData method (just before to register the controller as observer for the notification) solves the problem.

Thanks for your help, Peter. And thanks to Fred McCann's for its valuable blog post !


I was working on importing of record & display of records in tableview. Faced same issue when I tried to save record on backgroundThread like below

 [self performSelectorInBackground:@selector(saveObjectContextInDataBaseWithContext:) withObject:privateQueueContext];

while I already created a PrivateQueueContext. Just replace above code with below one

[self saveObjectContextInDataBaseWithContext:privateQueueContext];

Really it was my foolish work to save on background thread while I already created a privateQueueConcurrencyType for saving record.