Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are using the private concurrency type. That means, you should run the code on its own queue (via performBlock). So, if you want to do that, you should do it like this...</p> <pre><code>NSManagedObjectContext * backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; backgroundContext.parentContext = self.eventDatabase.managedDocument; backgroundContext.performBlock:^{ //here goes some code for downloading data from the server //some code for creating objects in backgroundContext NSLog(@"inserting data in background thread"); // Calling save on the background context will push the changes up to the document. NSError *error = nil; [backgroundContext save:&amp;error]; // Now, the changes will have been pushed into the MOC of the document, but // the auto-save will not have fired. You must make this call to tell the document // that it can save recent changes. [self.eventDatabase updateChangeCount:UIDocumentChangeDone]; }); </code></pre> <p>If you want to manage the queue yourself, you should probably use a confinement MOC, you should init with NSConfinementConcurrencyType, or with the standard init, because that's the default. Then, it would look like this...</p> <pre><code>dispatch_queue_t fetchQ = dispatch_queue_create("Data fetcher", NULL); dispatch_async(fetchQ, ^{ backgroundContext.parentContext = self.eventDatabase.managedDocument; //here goes some code for downloading data from the server NSManagedObjectContext * backgroundContext = [[NSManagedObjectContext alloc] init]; // Everything else is as in the code above for the private MOC. }); dispatch_release(fetchQ); </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