If we use CoreData in a multithreaded applications, we must take count of the following. A NSManagedObject created in one thread, can’t be used in another thread. Also a NSManagedObjectContext can’t be used inter threads.
Two practices are recommended when programming with threads and CoreData:
- Create a new NSManagedObjectContext for each thread. The object NSPersistentStore can be shared among thread safely.
- When is necessary sharing a NSManagedObject between threads, share its objectID property only. Then query that object with method:
As apple say:
PS: Remember that when using asynchronous request -either using blocks or delegates-, always is used a different thread for the response treatment.