1
votes

I am also interested in understating how iOS 5+ parent contexts work. I am using RestKit 0.2x but I think these are general Core Data questions.

Let's say we have this store coordinator/contexts hierarchy:

Persistent Store Coordinator (PSC) -> PS Managed Object Context (PS-MOC) -> Main Queue MOC (MQ-MOC).

For a request RestKit creates a temporary Private Context (P-MOC) from MQ-MOC and on success by default saves the changes back all the way to the PSC:

PSC -> PS-MOC -> MQ-MOC [-> P-MOC]

I also manually create managed objects and modify properties directly on the MQ-MOC.

My questions:

  • Are my unsaved MQ-MOC changes passed to child P-MOQ when created?
  • Should I save my MQ-MOC changes before a child P-MOQ gets created? Should I save these changes all the way to the PSC?
  • If P-MOQ is configured to save only to its parent MQ-MOC context, the newly introduced changes look like my MQ-MOC unsaved changes?
1

1 Answers

2
votes

Are my unsaved MQ-MOC changes passed to (an existing) child P-MOQ?

Unsaved, never. Saved, no, because they aren't required there so RestKit doesn't check and merge the changes.

How about unsaved changes when the child P-MOQ is created?

Anything saved in the parent when the child is created will be available in the child.

Should I save my MQ-MOC changes before a child P-MOQ gets created?

If the child needs them, yes (though in theory RestKit should detect that an object you use in a request isn't saved and save it for you, best not to rely on that).

Should I save these changes all the way to the PSC?

Yes. Having things saved but not persisted will just lead to issues in the future.

If P-MOQ is configured to save only to its parent MQ-MOC context, the newly introduced changes look like my MQ-MOC unsaved changes?

A child will push changes up to its direct parent but no further, so in effect, yes.

Just to check, you should be aware of the RestKit added method saveToPersistentStore:.