Add blocking variant to save method

This commit is contained in:
Saul Mora
2012-12-10 17:18:56 -07:00
parent b10734f074
commit ca7f5f09ee
2 changed files with 16 additions and 8 deletions

View File

@@ -10,6 +10,7 @@
@interface NSManagedObjectContext (MagicalSaves)
- (void) MR_blockingSave;
- (void) MR_save;
- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback;

View File

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