views:

154

answers:

1

You have to have one per thread, but beyond that ... should you have more? Is it harmful to have more?

For instance, I'm tempted to build my app around having one NSManagedObjectContext per tab, handling the subset of the overall persistent store that appears on that particular tab.

That way, I can have the tab GUI listen to notificataions on "its" context, and ignore others. Asynch network calls will change just one tab's context at a time.

(NB: not using NSFetchController because of the major bugs in that class pre iOS 3.2, and this is a 3.0+ app)

Have I misunderstood how to use NSManagedObjectContext? If so, can anyone point out "good"/"bad" reasons for using additional NSManagedObjectContext instances?

UPDATE: this worked fine for discrete contexts, but when I tried to extrapolate to using multiple contexts on one set of data, to handle temporary changes, it all goes horribly wrong: c.f. question on that topic: http://stackoverflow.com/questions/3173488/how-to-make-use-temporary-nsmanagedobjects

A: 

It is possible, yes, but be aware that you have to deal with merging them properly and making sure that you don't have stale data between contexts.

Jason Coco
My plan is that there's no shared data between the contexts; each tab has a unique subset of the data store (same data types, just different subsets of data).This *seems* like it might what Apple intended ... maybe ... but then again, they don't seem to offer an answer, so I have no idea if this will go horribly wrong!
Adam
@Adam Given those restrictions, you should be fine using several contexts.
calmh