Permalink
Browse files

Notify when no changes have been saved in context

Fix completion callback not firing when no changes in context
  • Loading branch information...
1 parent 4cb9564 commit e70c89baa1e6adf1875f536335ba6797e3ddcd77 @casademora casademora committed May 29, 2012
View
8 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m
@@ -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;
@@ -89,7 +95,7 @@ - (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback comp
{
[self performBlock:^{
[self MR_saveWithErrorCallback:errorCallback];
-
+
if (completion)
{
completion();
View
5 MagicalRecord/Core/MagicalRecord+Actions.m
@@ -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];
});
}

0 comments on commit e70c89b

Please sign in to comment.