我想在 dispatch_group_notify 完成后得到一个布尔值。不幸的是,下面的代码是错误的,我不知道该怎么做......编译器告诉我“不兼容的块指针类型将'BOOL'(^)(void)'传递给'dispatch_block_t'类型的参数(又名' void(^)(void^))" 有什么想法吗?
-(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;
});
}