Persist changes to disk when using:

- [NSManagedObjectContext MR_saveInBackgroundErrorHandler:completion:] methods, AND the context is the default context
- [MagicalRecord saveInBackground…] methods
This commit is contained in:
Saul Mora
2012-07-01 14:49:11 -05:00
parent f696791d9d
commit 8bb0d0de74
3 changed files with 16 additions and 9 deletions

2
.gitignore vendored
View File

@@ -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

View File

@@ -91,21 +91,26 @@
[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

View File

@@ -66,12 +66,12 @@ void reset_action_queue(void)
if ([localContext hasChanges])
{
[localContext MR_saveErrorHandler:errorHandler];
[localContext MR_saveNestedContextsErrorHandler:errorHandler];
}
if (completion)
{
completion();
dispatch_async(dispatch_get_main_queue(), completion);
}
}