let publisherE = PassthroughSubject<String, Never>() let publisherF = PassthroughSubject<String, Never>() let publishers = PassthroughSubject<PassthroughSubject<String, Never>,Never>() publishers.switchToLatest().sink { print($0) } publishers.send(publisherE) publisherE.send("Publisher E - Value 1") //Publisher E - Value 1 publisherE.send("Publisher E - Value 2") //Publisher E - Value 2 publishers.send(publisherF) // switching to publisher 2 publisherF.send("Publisher F - Value 1") //Publisher F - Value 1 publisherE.send("Publisher E - Value 3") //
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter