Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NSPersistentStoreCoordinator *coordinator = [appDelegate persistentStoreCoordinator];
  2. NSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] init];
  3. [newContext setPersistentStoreCoordinator:coordinator];
  4.    
  5. [[NSNotificationCenter defaultCenter] addObserver:appDelegate selector:@selector(contextDidSaveFromSeparateThread:) name:NSManagedObjectContextDidSaveNotification object:newContext];
  6.  
  7. // model work done here
  8.  
  9. // when this executes the notification fires which should execute contextDidSaveFromSeparateThread: which then merges the contexts
  10. if (![newContext save:&saveError]) {
  11.     NSLog(@"ERROR saving in registerTheUser: %@", saveError);
  12. }
  13.  
  14. [[NSNotificationCenter defaultCenter] removeObserver:appDelegate name:NSManagedObjectContextDidSaveNotification object:newContext];
  15.  
  16. [newContext release], newContext = nil;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement