Skip to content

Instantly share code, notes, and snippets.

@lemonkey
Forked from quellish/saveManagedObjectContext.m
Created October 28, 2016 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemonkey/684f47ea429d0581c283d587fe850ad8 to your computer and use it in GitHub Desktop.
Save lemonkey/684f47ea429d0581c283d587fe850ad8 to your computer and use it in GitHub Desktop.
Recursive save of managed object context
- (void) saveManagedObjectContext:(NSManagedObjectContext *)managedObjectContext withCompletion::(void (^)(BOOL, NSError *))completio{
managedObjectContext performBlock:^{
NSError *error = nil;
if (![managedObjectContext save:&error]){
completion(NO, error);
} else {
if ([managedObjectContext parentContext] != nil){
[self saveManagedObjectContext:[managedObjectContext parentContext] withCompletion:completion];
} else {
completion(YES, error);
}
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment