One Logo Pool Ball
Combine · IOS API REFERENCE

Publishers.SwitchToLatest

struct · iOS 13.0+ · SDK 27.1

struct SwitchToLatest<P, Upstream> where P : Publisher, P == Upstream.Output, Upstream : Publisher, P.Failure == Upstream.Failure

A publisher that flattens nested publishers. Given a publisher that publishes ``Publisher`` instances, the ``Publishers/SwitchToLatest`` publisher produces a sequence of events from only the most recent one. For example, given the type `AnyPublisher<URLSession.DataTaskPublisher, NSError>`, calling ``Publisher/switchToLatest()`` results in the type `SwitchToLatest<(Data, URLResponse), URLError>`. The downstream subscriber sees a continuous stream of `(Data, URLResponse)` elements from what looks like a single <doc://com.apple.documentation/documentation/Foundation/URLSession/DataTaskPublisher> even though the elements are coming from different upstream publishers. When ``Publishers/SwitchToLatest`` receives a new publisher from the upstream publisher, it cancels its previous subscription. Use this feature to prevent earlier publishers from performing unnecessary work, such as creating network request publishers from frequently-updating user interface publishers.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Publishers.SwitchToLatest.upstream

This declaration needs Swift generic type arguments. (no canonical witness for Upstream)

Publishers.SwitchToLatest.init(upstream:)

This declaration needs Swift generic type arguments. (no canonical witness for Upstream)

Publishers.SwitchToLatest.receive(subscriber:)

This declaration needs Swift generic type arguments. (no canonical witness for S)

All Combine types →