Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Persist changes to disk when using:

- [NSManagedObjectContext MR_saveInBackgroundErrorHandler:completion:] methods, AND the context is the default context
- [MagicalRecord saveInBackground…] methods
  • Loading branch information...
commit 8bb0d0de7428c376b6561b289eca7fb1a261d05a 1 parent f696791
Saul Mora casademora authored
2  .gitignore
View
@@ -19,3 +19,5 @@ UserInterfaceState.xcuserstate
/Magical Record.xcodeproj/xcuserdata/saul.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
/Magical Record.xcodeproj/xcuserdata/gfurman.xcuserdatad
Project Files/Magical Record.xcodeproj/xcuserdata
+Project Files/MagicalRecord.xcodeproj/xcuserdata/saul.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
+Project Files/MagicalRecord.xcodeproj/xcuserdata/saul.xcuserdatad/xcschemes/iOS Test Runner.xcscheme
19 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m
View
@@ -91,21 +91,26 @@ - (void) MR_saveInBackgroundCompletion:(void (^)(void))completion;
[self MR_saveInBackgroundErrorHandler:nil completion:completion];
}
+- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback;
+{
+ [self MR_saveInBackgroundErrorHandler:errorCallback completion:nil];
+}
+
- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion;
{
[self performBlock:^{
[self MR_saveWithErrorCallback:errorCallback];
-
- if (completion)
+
+ if (self == [[self class] MR_defaultContext])
+ {
+ [[[self class] MR_rootSavingContext] MR_saveInBackgroundErrorHandler:errorCallback completion:completion];
+ }
+
+ if (self == [[self class] MR_rootSavingContext])
{
dispatch_async(dispatch_get_main_queue(), completion);
}
}];
}
-- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback;
-{
- [self MR_saveInBackgroundErrorHandler:errorCallback completion:nil];
-}
-
@end
4 MagicalRecord/Core/MagicalRecord+Actions.m
View
@@ -66,12 +66,12 @@ + (void) saveWithBlock:(void (^)(NSManagedObjectContext *localContext))block com
if ([localContext hasChanges])
{
- [localContext MR_saveErrorHandler:errorHandler];
+ [localContext MR_saveNestedContextsErrorHandler:errorHandler];
}
if (completion)
{
- completion();
+ dispatch_async(dispatch_get_main_queue(), completion);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.