Is it OK to have multiple NSManagedObjectContext instances per thread?
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: How to make/use temporary NSManagedObjects?
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.
精彩评论