5

From Apple's Core Data Programming Guide:

You should give each thread its own entirely private managed object context and keep their associated object graphs separated on a per-thread basis.

How does that scale to Grand Central Dispatch, where you have absolutely no control over threads, which are created automagically on your behalf?

The way I do it now is to have one NSManagedObjectContext for each dispatch queue, but that's the thing: a dispatch queue doesn't necessarily use the same thread every time, right?

samvermette
  • 40,269
  • 27
  • 112
  • 144
  • 1
    possible duplicate of [What does Apple mean when they say that a NSManagedObjectContext is owned by the thread or queue that created it?](http://stackoverflow.com/questions/4800889/what-does-apple-mean-when-they-say-that-a-nsmanagedobjectcontext-is-owned-by-the) – Brad Larson Apr 04 '11 at 00:15
  • 1
    As Nick points out, the other question has a few pretty good explanations for this (particularly Ben's). Also, without breaking NDA, you may wish to read about what's changed in Lion for Core Data (which I assume will find its way to iOS 5.0). – Brad Larson Apr 04 '11 at 00:21

2 Answers2

2

I think "What does Apple mean when they say that a NSManagedObjectContext is owned by the thread or queue that created it?" on SO will answer your question.

Community
  • 1
  • 1
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
0

I have not looked at this article, but maybe you are interested in this post Passing around a NSManagedObjectContext on the iPhone by Marcus Zara.

Hoang Pham
  • 6,899
  • 11
  • 57
  • 70