调用wait()
let group = DispatchGroup()
let queue1 = DispatchQueue(label: "haha", attributes: .concurrent)
let queue2 = DispatchQueue(label: "hahaha", attributes: .concurrent)
queue1.async(group: group) {
print("任务1")
}
queue2.async(group: group) {
print("任务2")
}
queue1.async(group: group) {
print("任务3")
}
queue2.async(group: group) {
print("任务4")
}
group.wait()
print("任务------")
运行结果:
任务1
任务3
任务4
任务2
任务------