面试经常有被问到,如果我需要下载十张图片,当十张图片下载完成之后需要做一个日志输出
下面模拟一下
获取全局队列
dispatch_queuq_t globalQueue = dispatch_get_global_queue(0,0);
创建一个任务组
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group,global,^{
sleep(1);
NSLog(@">>>>>>>>>>>>1");
});
dispatch_group_async(group,global,^{
sleep(5);
NSLog(@">>>>>>>>>>>>2");
});
dispatch_group_async(group,global,^{
sleep(3);
NSLog(@">>>>>>>>>>>>3");
});
当组里面的任务全都执行完成之后才会执行
dispatch_group_notify(group,globalQueue,^{
NSLog(@"全都执行完成");
});
网友评论