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 moc
self.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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With