magicalpanda/MagicalRecord — Issue #132: executeInBackgroundWithBlock
Author: dav
Created: 2012-01-16 18:48:55+00:00
State: open

I wanted to run an arbritary block only after all of the existing blocks sent to [MRCoreDataAction saveDataInBackgroundWithBlock:] had completed. So I added a MRCoreDataAction category:

@interface MRCoreDataAction (Additions)
+ (void) executeInBackgroundWithBlock:(void(^)(void))block;
@end

#import "MRCoreDataAction.h"
#import "MRCoreDataAction+Additions.h"

extern dispatch_queue_t background_save_queue(void);

@implementation MRCoreDataAction (Additions)

+ (void) executeInBackgroundWithBlock:(void(^)(void))block {
dispatch_async(background_save_queue(), ^{
block();
});
}

@end

If you're interested, I could add to base object instead and create a pull request. Or maybe someone thinks it's a dumb idea and wants to tell me why :)