Flattens the stream of events from multiple upstream publishers to appear as if they were coming from a single stream of events.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
Framework
- Combine
Declaration
func switchToLatest() -> Publishers.Switch To Latest<Upstream.Output, Publishers.Try Comparison<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 switch
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.