一、DispatchGroup三种用法:
1. notify(依赖任务)
let group = DispatchGroup()
myQueue?.async(group: group, qos: .default, flags: [], execute: {
for _ in 0...10 {
print("耗时任务一")
}
})
myQueue?.async(group: group, qos: .default, flags: [], execute: {
for _ in 0...10 {
print("耗时任务二")
}
})
//执行完上面的两个耗时操作, 回到myQueue队列中执行下一步的任务
group.notify(queue: myQueue!) {
print("回到该队列中执行")
}
2. wait(任务等待)
let group = DispatchGroup()
myQueue?.async(group: group, qos: .default, flags: [], execute: {
for _ in 0...10 {
print("耗时任务一")
}
})
myQueue?.async(group: group, qos: .default, flags: [], execute: {
for _ in 0...10 {