mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-04-28 20:15:49 +08:00
Add blocking variant to save method
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
@interface NSManagedObjectContext (MagicalSaves)
|
||||
|
||||
- (void) MR_blockingSave;
|
||||
- (void) MR_save;
|
||||
- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback;
|
||||
|
||||
|
||||
@@ -20,6 +20,20 @@
|
||||
|
||||
@implementation NSManagedObjectContext (MagicalSaves)
|
||||
|
||||
- (void) MR_blockingSave;
|
||||
{
|
||||
[self performBlockAndWait:^{
|
||||
[self MR_saveWithErrorCallback:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) MR_save;
|
||||
{
|
||||
[self performBlock:^{
|
||||
[self MR_saveWithErrorCallback:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback;
|
||||
{
|
||||
if (![self hasChanges])
|
||||
@@ -34,9 +48,7 @@
|
||||
__block BOOL saved = NO;
|
||||
@try
|
||||
{
|
||||
[self performBlockAndWait:^{
|
||||
saved = [self save:&error];
|
||||
}];
|
||||
saved = [self save:&error];
|
||||
}
|
||||
@catch (NSException *exception)
|
||||
{
|
||||
@@ -85,11 +97,6 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) MR_save;
|
||||
{
|
||||
[self MR_saveWithErrorCallback:nil];
|
||||
}
|
||||
|
||||
- (void) MR_saveInBackgroundCompletion:(void (^)(void))completion;
|
||||
{
|
||||
[self MR_saveInBackgroundErrorHandler:nil completion:completion];
|
||||
|
||||
Reference in New Issue
Block a user