Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Currently [May 2015] the <a href="http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/coredata/Articles/cdConcurrency.html#//apple_ref/doc/uid/TP40003385-SW1">Apple Concurrency with Core Data documentation</a> is, at best, very misleading as it doesn't cover any of the enhancements in iOS 5 and hence no longer shows the best ways to use core data concurrently. There are two very important changes in iOS 5 - parent contexts and new concurrency/threading types.</p> <p>I have not yet found any written documentation that comprehensively covers these new features, but the <a href="https://developer.apple.com/videos/wwdc/2012/?id=214">WWDC 2012 video "Session 214 - Core Data Best Practices"</a> does explain it all very well.</p> <p><a href="https://github.com/magicalpanda/MagicalRecord/">Magical Record</a> uses these new features and may be worth a look.</p> <p>The real basics are still the same - you can still only use managed objects the thread their managed object context was created on.</p> <p>You can now use [moc performBlock:] to run code on the right thread.</p> <p>There's no need to use mergeChangesFromContextDidSaveNotification: anymore; instead create a child context to make the changes, then save the child context. Saving the child context will automatically push the changes up into the parent context, and to save the changes to disk just perform a save on the parent context in it's thread.</p> <p>For this to work you must create the parent context with a concurrent type, eg:</p> <pre><code>mainManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; </code></pre> <p>Then on the background thread:</p> <pre><code>context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSConfinementConcurrencyType]; [context setParentContext:mainManagedObjectContext]; &lt;... perform actions on context ...&gt; NSError *error; if (![context save:&amp;error]) { &lt;... handle error ...&gt; } [mainManagedObjectContext performBlock:^{ NSError *e = nil; if (![mainContext save:&amp;e]) { &lt;... handle error ...&gt; } }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload