Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, </p> <blockquote> <p>"how to pass the correct managed object context down to my custom NSManagedObjects."</p> </blockquote> <p>We create <code>NSManagedObject</code> with <code>NSManagedObjectContext</code>. not the other way around. So, when you have a <code>NSManagedObject</code>, you can access the <code>NSManagedObjectContext</code> by asking its property: <code>– managedObjectContext</code> as listed in <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html" rel="nofollow"><strong>Apple Document</strong></a> </p> <p>Second,</p> <p>When working with CoreData, multi-threading could be a little tricky. especially for the beginner. The are all kind of details that you need to take care of. </p> <p>I highly recommend you checkout the <code>Parent-Child NSManagedContext</code>. then, using <a href="https://github.com/magicalpanda/MagicalRecord" rel="nofollow"><strong>MagicRecord</strong></a>.</p> <p>By using <a href="https://github.com/magicalpanda/MagicalRecord" rel="nofollow"><strong>MagicRecord</strong></a>, you can simply Grand Central Dispatch with a Block like this:</p> <pre><code>[MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext){ // here use the `localContext` as your NSManagedContext and do things in the background. // it will take care of all the rest. }]; </code></pre> <p>If you need to pass <code>NSManagedObject</code> into this block, remember to only pass the <code>NSManagedObjectID</code> instead of the proprety.</p> <p>this is a example.</p> <pre><code>NSManagedObjectID *coaMapID = CoaMap.objectID; [MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext){ coaMap *aCoaMap = (coaMap *)[localContext existingObjectWithID:coaMapID error:&amp;error]; // then use aCoaMap normally. }]; </code></pre> <p>Hope this helped.</p>
    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. 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