간단하게 공식 문서 정리하기
그룹에 들어간 task 들이 모두 완료된 시점을 잡을 수 있다. → notify
활용 예시 및 코드
let animationGroup = DispatchGroup()
// enter
animationGroup.enter()
UIView.animate(withDuration: 1.5) {
self.view1.backgroundColor = .blue
} completion: { _ in
// leave
animationGroup.leave()
}
// enter
animationGroup.enter()
UIView.animate(withDuration: 3) {
self.view2.backgroundColor = .green
} completion: { _ in
// leave
animationGroup.leave()
}
// notify
animationGroup.notify(queue: .main) {
self.performSegue(withIdentifier: "nextSceneSegue", sender: nil)
}
[ ] RxSwift 의 zip 으로도 같은 문제를 해결할 수 있을 것 같다.
→ (1,a) ,,, (2,b),,, (3,c) = zip
→ (1,a),,(1,b),,(2,b),,(2,c),,(3,c) = combineLatest