最近在写的模块有这样一个问题,要保证所有block里面的东西全都回来之后再执行某一个
例如我要做完所有的数据库操作再刷新界面,数据库的内容很多,所有用到了group
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
dispatch_group_enter(group);
block{
dispatch_group_leave(group);
}
...
dispatch_group_enter(group);
block{
dispatch_group_leave(group);
}
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"完成 - %@", [NSThread currentThread]);
complete(nil);
});
});