My app periodically request updates for the objects I persist with Core Data
to a web service. I then need to update the objects I have in my main context (the one provided in AppDelegate
by default). It is not the user who edits the objects, so I need to avoid blocking the UI, and furthermore I'm not just modifying objects information, but deleting and adding new objects if needed.
It seems that there are two options to perform updates of NSManagedObject
objects: creating a "sibling" context in a private queue, and creating a child context. Reading several posts, there are more people saying that it is better to use parent/child contexts (correct me if I'm wrong), but I don't completely understand how that works. I have some questions regarding parent/child contexts:
- Can a child context be in a private queue and the parent context in the main queue?
- I've read somewhere something about setting a merge policy, but I didn't find examples of its use, maybe is not necessary to set a merge policy when usen parent/child contexts? When would they be set? Where can I find an example or tutorial?
- If I set my private context as child of the main context, and I save the child private context, will the objects in private context "replace" the objects in the main context as I want? (including deleting the objects that are no longer present in the private context and the new ones)... I mean... does the whole child context replace the whole parent context?
- Would it be better to save the private context without being a child of the main one, and then clearing and refetching all the new data in the main context?
I really need help with this issue, thanks in advance.