Guest User

Untitled

a guest
Jan 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. [MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext) {
  2. // Do this hundreds of times
  3. [MyObject createInContext:localContext];
  4. }];
  5.  
  6. [MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext) {
  7. // Do this hundreds of times
  8. [MyObject createInContext:localContext];
  9. } completion:^{
  10. [[NSOperationQueue mainQueue] addOperationWithBlock:^{
  11. [[NSManagedObjectContext defaultContext] saveNestedContexts];
  12. }];
  13. }];
  14.  
  15. self.queue = [[NSOperationQueue alloc] init];
  16.  
  17. [self.queue addOperationWithBlock:^{
  18. NSManagedObjectContext *localContext = [NSManagedObjectContext contextForCurrentThread];
  19.  
  20. // Do this hundreds of times
  21. [MyObject createInContext:localContext];
  22.  
  23. [localContext saveNestedContexts];
  24. }];
  25.  
  26. dispatch_queue_t syncQueue = dispatch_queue_create("Sync queue", NULL);
  27. dispatch_async(syncQueue, ^{
  28. NSManagedObjectContext *localContext = [NSManagedObjectContext contextForCurrentThread];
  29.  
  30. // Do this hundreds of times
  31. [MyObject createInContext:localContext];
  32.  
  33. [[NSManagedObjectContext contextForCurrentThread] saveNestedContexts];
  34. });
Add Comment
Please, Sign In to add comment