From 8bb0d0de7428c376b6561b289eca7fb1a261d05a Mon Sep 17 00:00:00 2001 From: Saul Mora Date: Sun, 1 Jul 2012 14:49:11 -0500 Subject: [PATCH] =?UTF-8?q?Persist=20changes=20to=20disk=20when=20using:?= =?UTF-8?q?=20-=20[NSManagedObjectContext=20MR=5FsaveInBackgroundErrorHand?= =?UTF-8?q?ler:completion:]=20methods,=20AND=20the=20context=20is=20the=20?= =?UTF-8?q?default=20context=20-=20[MagicalRecord=20saveInBackground?= =?UTF-8?q?=E2=80=A6]=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .../NSManagedObjectContext+MagicalSaves.m | 19 ++++++++++++------- MagicalRecord/Core/MagicalRecord+Actions.m | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 254085a..642b180 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m index 0354cd2..48bd6d3 100644 --- a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m +++ b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m @@ -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 diff --git a/MagicalRecord/Core/MagicalRecord+Actions.m b/MagicalRecord/Core/MagicalRecord+Actions.m index f0d5225..2416244 100644 --- a/MagicalRecord/Core/MagicalRecord+Actions.m +++ b/MagicalRecord/Core/MagicalRecord+Actions.m @@ -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); } }