I’ve got two core data objects: an Organization and a Person which are linked together.
Is it a problem if I change them in different threads and save them both? So the threads are running in parallel:
Thread 1:
– load Organization with NSManagedObjectID
– make changes to the object
– save object
Thread 2:
– load Person with NSManagedObjectID
– make changes to the object
– save object
For me it seems as if I got a mutex because of this; not every time, but sometimes it happens. If that’s the problem – what’s the solution? 🙂
Thanks a lot!
Stefan
Yes that is a problem if you are using the same NSManagedObjectContext. Core-Data, is not totally thread safe, NSManagedObjectID’s are. On your background thread you must create a separate context with the same store and then save, which notifies the main thread when it is saved to merge the two contexts. You can control this merging by creating merge policies. So you can still do it but not as easily as hoped.