views:

106

answers:

4

I don't get the point of having multiple Managed Object Contexts. Does that make any sense? The Apple documentation lacks of useful examples for these cases.

+5  A: 

Just one quick example :

If you get data from the web. You'd need a 2nd context to insert the new objects and check if the data exists in your main context before merging data and save only your main context.

F.Santoni
+2  A: 

Santoni's answer is the primary reason.

You can also have multiple unrelated models (MOMs). In that case you would have context for each model.

Corey Floyd
+5  A: 

The most important use (IMHO) is threading; if you're using multiple threads, each thread should have its own managed object context.

Ben Gottlieb
This goes hand in hand with Santoni's answer. Starting a background thread to add multiple new objects to the store.
Corey Floyd
A: 

Just to throw another possible use case on the pile: NSManagedObjectContexts also maintain their own "undo" states, so if you wanted to keep sequences of changes separate for some reason then that would be one way to do it. For example you might apply different changes to context's A and B, then throw A away before saving B.

Nimrod