Skip to content

Instantly share code, notes, and snippets.

@AlanQuatermain
Created July 28, 2011 18:44
Show Gist options
  • Save AlanQuatermain/1112224 to your computer and use it in GitHub Desktop.
Save AlanQuatermain/1112224 to your computer and use it in GitHub Desktop.
The change that fixed a HORRENDOUS CoreData-related bug which we've been chasing today.
[managedObjectContext setMergePolicy: NSMergeByPropertyObjectTrumpMergePolicy];
[managedObjectContext setPersistentStoreCoordinator: coordinator];
- StoreManagedObjectContextForCurrentThread( managedObjectContext ); // store in thread dictionary
+
+ if ( [NSThread isMainThread] )
+ StoreManagedObjectContextForCurrentThread(managedObjectContext); // store in thread dictionary
+ else
+ dispatch_sync(dispatch_get_main_queue(), ^{ StoreManagedObjectContextForCurrentThread(managedObjectContext); });
// set some flags in the store metadata
NSPersistentStore * store = [[coordinator persistentStores] lastObject];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment