Skip to content

Commit

Permalink
Notify when no changes have been saved in context
Browse files Browse the repository at this point in the history
Fix completion callback not firing when no changes in context
  • Loading branch information
casademora committed May 29, 2012
1 parent 4cb9564 commit e70c89b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Expand Up @@ -22,6 +22,12 @@ @implementation NSManagedObjectContext (MagicalSaves)

- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback;
{
if (![self hasChanges])
{
MRLog(@"NO CHANGES IN CONTEXT %@ - NOT SAVING", [self MR_description]);
return;
}

MRLog(@"-> Saving %@", [self MR_description]);

NSError *error = nil;
Expand Down Expand Up @@ -89,7 +95,7 @@ - (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback comp
{
[self performBlock:^{
[self MR_saveWithErrorCallback:errorCallback];

if (completion)
{
completion();
Expand Down
5 changes: 1 addition & 4 deletions MagicalRecord/Core/MagicalRecord+Actions.m
Expand Up @@ -38,10 +38,7 @@ + (void) saveInBackgroundUsingContext:(NSManagedObjectContext *)localContext blo
dispatch_async(action_queue(), ^{
block(localContext);

if ([localContext hasChanges])
{
[localContext MR_saveInBackgroundErrorHandler:errorHandler completion:completion];
}
[localContext MR_saveInBackgroundErrorHandler:errorHandler completion:completion];
});
}

Expand Down

0 comments on commit e70c89b

Please sign in to comment.