objective-cioscore-datamocmanagedobjectcontext

Is it possible to reuse one shared managed object context beetween threads, when each thread can work with data not related to data in other thread?


Simple example for the title question: one thread has prepared Place entity and is doing some processing on it (filling particular fields and their calculation takes time) and in the mean time the other thread has already prepared Category entity; the second "Category" thread wants to persist Category entity with save:&error causing Place entity from the first thread to be saved also while it didn't finished its processing job.

Am I right? Will I see the problem described if I use one shared moc?

Thanks!


Solution

  • Do not share NSManagedObjectContexts across threads. Do not share NSManagedObjects across threads. There really are no exceptions. Read Concurrency with Core Data and apply the patterns it describes.