diff --git a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.h b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.h index 3da523b..5c15ef6 100644 --- a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.h +++ b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.h @@ -11,7 +11,7 @@ @interface NSManagedObjectContext (MagicalSaves) - (void) MR_save; -- (void) MR_saveErrorHandler:(void (^)(NSError *))errorCallback; +- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback; - (void) MR_saveInBackgroundCompletion:(void (^)(void))completion; - (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback; diff --git a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m index e0ff4d8..aec15ad 100644 --- a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m +++ b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m @@ -88,18 +88,7 @@ - (void) MR_save; { - [self MR_saveErrorHandler:nil]; -} - -- (void) MR_saveErrorHandler:(void (^)(NSError *))errorCallback; -{ - [self performBlockAndWait:^{ - [self MR_saveWithErrorCallback:errorCallback]; - - [[self parentContext] performBlockAndWait:^{ - [[self parentContext] MR_saveErrorHandler:errorCallback]; - }]; - }]; + [self MR_saveWithErrorCallback:nil]; } - (void) MR_saveInBackgroundCompletion:(void (^)(void))completion; diff --git a/MagicalRecord/Core/MagicalRecord+Actions.m b/MagicalRecord/Core/MagicalRecord+Actions.m index 0f5a7e2..2e56bbb 100644 --- a/MagicalRecord/Core/MagicalRecord+Actions.m +++ b/MagicalRecord/Core/MagicalRecord+Actions.m @@ -8,38 +8,15 @@ #import "CoreData+MagicalRecord.h" #import "NSManagedObjectContext+MagicalRecord.h" -static dispatch_queue_t background_action_queue; - -dispatch_queue_t action_queue(void); -dispatch_queue_t action_queue(void) -{ - if (background_action_queue == NULL) - { - background_action_queue = dispatch_queue_create("com.magicalpanda.magicalrecord.actionQueue", DISPATCH_QUEUE_SERIAL); - } - - return background_action_queue; -} - -void reset_action_queue(void); -void reset_action_queue(void) -{ - if (background_action_queue != NULL) - { - MRDispatchQueueRelease(background_action_queue); - background_action_queue = NULL; - } -} - @implementation MagicalRecord (Actions) + (void) saveInBackgroundUsingContext:(NSManagedObjectContext *)localContext block:(void (^)(NSManagedObjectContext *))block completion:(void(^)(void))completion errorHandler:(void(^)(NSError *))errorHandler; { - dispatch_async(action_queue(), ^{ + [localContext performBlock: ^{ block(localContext); [localContext MR_saveNestedContextsErrorHandler:errorHandler completion:completion]; - }); + }]; } + (void) saveInBackgroundWithBlock:(void (^)(NSManagedObjectContext *))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *))errorHandler; @@ -66,7 +43,7 @@ void reset_action_queue(void) if ([localContext hasChanges]) { - [localContext MR_saveErrorHandler:errorHandler]; + [localContext MR_saveWithErrorCallback:errorHandler]; } if (completion) diff --git a/MagicalRecord/Core/MagicalRecord.m b/MagicalRecord/Core/MagicalRecord.m index 9616db7..42d577a 100644 --- a/MagicalRecord/Core/MagicalRecord.m +++ b/MagicalRecord/Core/MagicalRecord.m @@ -20,7 +20,6 @@ @end -void reset_action_queue(void); @implementation MagicalRecord @@ -28,7 +27,6 @@ void reset_action_queue(void); { [self cleanUpErrorHanding]; [self cleanUpStack]; - reset_action_queue(); } + (void) cleanUpStack;