Note that there are some explanatory texts on larger screens.

plurals
  1. POMultithread core data merge error
    text
    copied!<p>The standard way of using multithread core-data is </p> <pre><code>[mainContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:notification waitUntilDone:YES]; </code></pre> <p>However, the one have external managed object that save immediately after another. This creates errors. For example:</p> <pre><code>- (void)mergeChanges:(NSNotification *)notification { NSManagedObjectContext *mainContext = [self managedObjectContext]; // Merge changes into the main context on the main thread [mainContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:notification waitUntilDone:YES]; } - (void) loadingIntoCoreData { NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] init]; [ctx setUndoManager:nil]; [ctx setPersistentStoreCoordinator: [self persistentStoreCoordinator]]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(mergeChanges:) name:NSManagedObjectContextDidSaveNotification object:ctx]; ... // Create many objects [ctx save:&amp;error]; [self doSomethingWithThisCtx:ctx]; } - (void) doSomethingWithThisCtx:(NSManagedObjectContext *)ctx{ // Form relationships with objects create in - (void) loadingIntoCoreData [ctx save:&amp;error]; } </code></pre> <p>Then on the second [ctx save:&amp;error] will throw an "EXC_BAD_ACCESS" error.</p> <p>How would one insert into core data and create relationships with the new objects on a separate thread? It works fine on the main thread but since it's done during <code>applicationDidLaunched</code>, then the UI get locked up.</p>
 

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