Instance Method

switchToLatest()

Flattens the stream of events from multiple upstream publishers to appear as if they were coming from a single stream of events.

Declaration

func switchToLatest() -> Publishers.SwitchToLatest<Upstream.Output, Publishers.Share<Upstream>>
Available when Failure is Output.Failure and Output conforms to Publisher.

Discussion

This operator switches the inner publisher as new ones arrive but keeps the outer one constant for downstream subscribers. For example, given the type Publisher<Publisher<Data, NSError>, Never>, calling switchToLatest() will result in the type Publisher<Data, NSError>. The downstream subscriber sees a continuous stream of values even though they may be coming from different upstream publishers.