본문 바로가기

iOS/Combine

Zip Combines elements from two other publishers and delivers groups of elements as tuples. 다른 두 퍼블리셔로 부터 값을 묶어서 튜플형태로 방출한다(단, zip은 각 퍼블리셔들의 값이 동일할 때만 묶어 방출한다) zip.sink(receiveValue: { result in print("zip: \\(result.0), \\(result.1)") }) .store(in: &cancellables) left.send("Left") right.send("Right") right.send("Right2") left.send("Left2") // 결과값 zip: Left, Right zip: Left2, Right2 combineLatest와 마찬.. 더보기
CombineLatest Subscribes to an additional publisher and publishes a tuple upon receiving output from either publisher. 추가의 퍼블리셔 를 연결하여 Tuple 형태로 묶어서 값을 방출하는 연산자 var cancellables: Set = [] let left = PassthroughSubject() let right = PassthroughSubject() let combineLatest = Publishers.CombineLatest(left, right) combineLatest.sink(receiveValue: { result in print("combineLatest: \\(result.0), \\(result.1)") }) .s.. 더보기
WithLatestFrom Combines the source Observable with other Observables to create an Observable whose values are calculated from the latest values of each, only when the source emits AObservable.withLatestFrom(BObservable) 일 경우 A,B Source(A)값이 방출될때마다 A,B의 최신값을 묶어서 방출하는 오퍼레이터. A,B가 모두 방출 된 상태에서만 A 방출 시 값이 방출되며, Source가 아닌 B는 최신값만 트래킹하며 값을 방출하는 이벤트는 없다. 즉, A,B모두 방출되었고, A 방출 이벤트가 발생하면 A,B의 최신 값을 묶어서 방출한다. inputs.num.. 더보기