Combine: Combining Operators

PHOTO EMBED

Sun Jun 05 2022 22:15:33 GMT+0000 (Coordinated Universal Time)

Saved by @leo #swift

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") //
content_copyCOPY

https://www.createwithswift.com/reference-combine-combining-operators/