Last active
February 27, 2020 12:30
-
-
Save ramunasjurgilas/a24daa59c995fb5989e71436080b2a1b to your computer and use it in GitHub Desktop.
Combining operator: switchToLatest()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let intPublisher1 = PassthroughSubject<Int, Never>() | |
let intPublisher2 = PassthroughSubject<Int, Never>() | |
let publishers = PassthroughSubject<PassthroughSubject<Int, Never>, Never>() | |
publishers.switchToLatest().sink { print($0) } | |
publishers.send(intPublisher1) | |
intPublisher1.send(-3) | |
intPublisher1.send(-5) | |
intPublisher2.send(0) // Zero will not be published as publisher listening for latest publisher. | |
publishers.send(intPublisher2) | |
intPublisher2.send(100) | |
intPublisher2.send(200) | |
// Output: | |
// -3 | |
// -5 | |
// 100 | |
// 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment