Publishers.Collect
let subject = PassthroughSubject<Int, Error>()
// Publishers.Collect Publisher
Publishers.Collect(upstream: subject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Collect Error")
case .finished:
print("Combine Collect Finish")
}
}, receiveValue: { value in
print("Combine Collect : \(value)")
})
.store(in: &cancellables)
// collect Operator
subject
.collect()
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Collect Error")
case .finished:
print("Combine Collect Finish")
}
}, receiveValue: { value in
print("Combine Collect : \(value)")
})
.store(in: &cancellables)
// 1
subject.send(1)
subject.send(2)
subject.send(completion: .finished)
// Combine Collect : [1, 2]
// Combine Collect Finish
// 2
subject.send(1)
subject.send(completion: .failure(error))
// Combine Collect ErrorRxSwift
ReactiveSwift
μ°Έκ³
Last updated