标签:queue dispatch addition 今天 evel group 也有 blank glob
今天被一个问题纠结了2个小时。一開始失败的代码大概是这种:
dispatch_group_t group = dispatch_group_create(); while([rs next]){ dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{ [httpHelper getSecure:url completionHandler:^(NSDictionary* dict){ // 子任务 }]; }); } dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{ // 子任务所有完毕后。才运行 });
或者换一种写法。把dispatch_group_async写到getSecure的callback里面,也不行
最后最终找到一个救命帖:
gcd dispatch groups with an additional level of inception
应该写成这样:
dispatch_group_t group = dispatch_group_create(); while([rs next]){ dispatch_group_enter(group); dispatch_async(dispatch_get_global_queue(0, 0), ^{ [httpHelper getSecure:url completionHandler:^(NSDictionary* dict){ // 子任务 dispatch_group_leave(group); }]; }); } dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{ // 子任务所有完毕后。才运行 });
标签:queue dispatch addition 今天 evel group 也有 blank glob
原文地址:http://www.cnblogs.com/clnchanpin/p/6853564.html