Predict the output
What does this print?
let a = PassthroughSubject<Int, Never>()
let b = PassthroughSubject<String, Never>()
a.zip(b)
.sink { print($0, $1) }
.store(in: &cancellables)
a.send(1)
a.send(2)
b.send("x")
b.send("y")Hint 1 of 1
Pair the first with the first.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B 1 x, 2 y
Correct. zip pairs values by position.
Why not the others?
- A 2 x, 2 y. That is combineLatest-style behaviour.
- C 1 x. The second pair is complete once y arrives.
- D 1, 2, x, y. That is merge, which needs matching types.