mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-01-12 09:13:42 +08:00
Merging with origin/develop
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user