Some developers already told me that I can create a new NSManagedObjectContext instance for every new thread, to make Core Data thread-safe. Then I would just have to take care of the merging afterwards.
For me, this sounds like A LOT of extra code and overhead.
Is there a reason why this solution would be bad? Here it comes:
Instead of creating a new MOC for every new thread or for every NSOperation, I would perform MOC-changes on the Main Thread, just like we know from UIKit. I would just call -performSelectorOnMainThread:...waitUntilDone:YES and get rid of all Core Data concurrency issues.
Pros: - Don't have to create a new MOC for every Thread / NSOperation. - Don't have to merge MOCs together. - For sure no concurrency issue since Core Data stays on the Main thread where it is safe.
Cons:
- Calls like -performSelectorOnMainThread:...waitUntilDone:YES look ugly, hard to read.
- Thread / NSOperation gets blocked. But in reality, the system can't do multiple things at once anyways. In my case, the Core Data part is not the performance bottleneck. It's the heavy calculations around it that go in a background thread or NSOperation.
What do you think? Is this worth exploring further? Why would you still prefer to create a MOC for every new Thread / NSOperation and then deal with merging? What's the advantage of this compared to doing it on the Main thread?