Publishers.Zip
let aSubject = PassthroughSubject<Int, Never>()
let bSubject = PassthroughSubject<String, Never>()
// 1. Publishers.Zip Publisher
Publishers
.Zip(aSubject, bSubject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Zip Error")
case .finished:
print("Combine Zip Finish")
}
}, receiveValue: { value in
print("Combine Zip : \(value)")
})
.store(in: &cancellables)
// Combine Zip : (1, "a")
// Combine Zip : (2, "b")
// 2. zip Operator
aSubject
.zip(bSubject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Zip Error")
case .finished:
print("Combine Zip Finish")
}
}, receiveValue: { value in
print("Combine Zip : \(value)")
})
.store(in: &cancellables)
// Combine Zip : (1, "a")
// Combine Zip : (2, "b")
// 3. zip Operator
aSubject
.zip(bSubject) { "\($0)\($1)" }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Zip Error")
case .finished:
print("Combine Zip Finish")
}
}, receiveValue: { value in
print("Combine Zip : \(value)")
})
.store(in: &cancellables)
// Combine Zip : 1a
// Combine Zip : 2b
// 4
aSubject.send(1)
// 5
aSubject.send(2)
// 6
bSubject.send("a")
// 7
bSubject.send("b")
// 8
aSubject.send(3)RxSwift
ReactiveSwift
μ°Έκ³
Last updated