I'd like to get a bool value after dispatch_group_notify finished. Unfortunately, the following code is wrong, and I have no idea on how to do it... Compilator tell me "Incompatible block pointer types passing 'BOOL'(^)(void)' to parameter of type 'dispatch_block_t'(aka 'void(^)(void^))" Any idea?
-(BOOL)saveToDB:(NSArray*)data{
// execute async the saveJSONDictionary
__block BOOL toReturn;
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_queue_create("saveJsonDictionary", 0);
dispatch_group_async(group, queue, ^{
for (int i = 0; i < [data count]; ++i) {
NSDictionary* item = (NSDictionary*)[data objectAtIndex:i];
[self saveJsonDictionary:item];
}
NSManagedObjectContext *moc = [[DatabaseManager sharedManager]managedObjectContext];
toReturn = [moc save:nil];
});
dispatch_group_notify(group, queue, ^BOOL{
return toReturn;
});
}