GCD 调度组-oc
- 调度组是最重要的一监听一组任务的完成
- 创建调度组
- 创建队列
- 调度组监听队列调度任务
```
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t que = dispatch_get_global_queue(0, 0);
dispatch_async(que, ^{
NSLog(@"aaaaa%@",[NSThread currentThread]);
});
dispatch_async(que, ^{
NSLog(@"bbbbb%@",[NSThread currentThread]);
});
dispatch_async(que, ^{
NSLog(@"ccccccc%@",[NSThread currentThread]);
});
dispatch_group_notify(group, que, ^{
NSLog(@"come herer%@",[NSThread currentThread]);
});
```
<!--{% asset_img GCD调度组1.png %}-->

-
调度的入组出组
-
入组,出组,相互对应,不多不少。
dispatch_group_t group = dispatch_group_create(); dispatch_queue_t que = dispatch_get_global_queue(0, 0); dispatch_group_enter(group); // 入组 dispatch_async(que, ^{ NSLog(@"aaaaa%@",[NSThread currentThread]); dispatch_group_leave(group); // 出组 }); dispatch_group_enter(group); dispatch_async(que, ^{ NSLog(@"bbbbb%@",[NSThread currentThread]); dispatch_group_leave(group); }); dispatch_group_enter(group); dispatch_async(que, ^{ NSLog(@"ccccccc%@",[NSThread currentThread]); dispatch_group_leave(group); }); dispatch_group_notify(group, que, ^{ NSLog(@"come herer%@",[NSThread currentThread]); });
GCD 调度组-swift
-
为了监听所有图像缓存,使用DispatchGroup
-
enter 之后跟随block
-
block 中有leave,配对存在
func textGroup(){ let group = DispatchGroup() let queue = DispatchQueue.global() group.enter() queue.async { print("aaaaa\(Thread.current)") group.leave() } group.enter() queue.async { print("bbbbb\(Thread.current)") group.leave() } group.notify(queue: DispatchQueue.main) { print("come here is end \(Thread.current)") } }