What I want to do is create a async core data task on a background thread so as not to chew up the main thread, but I also want to do main thread work once the work is done...
Here's my task
-(void)doTaskwithCompletion:(coreDataCompletion)complete
{
[self.backgroundManagedObjectContext performBlock:^{
// do my BG core data task
[self saveContext:self.backgroundManagedObjectContext];
complete(YES);
}];
}
Here's my block method
[[MYCoreDataManager sharedInstance]doTaskwithCompletion:^(BOOL complete) {
if (complete == YES) {
dispatch_async(dispatch_get_main_queue(), ^{
// back to the main thread
});
}
}];
Something tells me this is wrong... but I can't find another way to put myself back on the main thread once the block has completed... notifications seem way too clunky.
I suppose in a nutshell my question is can I call dispatch_async(dispatch_get_main_queue()
inside moc performBlock:^
?
Essentially
-(void)doTaskwithCompletion:(coreDataCompletion)complete
{
[self.backgroundManagedObjectContext performBlock:^{
// do my BG core data task
[self saveContext:self.backgroundManagedObjectContext];
dispatch_async(dispatch_get_main_queue(), ^{
// back to the main thread
});
}];
}