---
title: switchToLatest()
framework: combine
role: symbol
role_heading: Instance Method
path: combine/publisher/switchtolatest()-9eb3r
---

# switchToLatest()

Republishes elements sent by the most recently received publisher.

## Declaration

```swift
func switchToLatest() -> Publishers.SwitchToLatest<Self.Output, Self>
```

## Discussion

Discussion This operator works with an upstream publisher of publishers, flattening the stream of elements to appear as if they were coming from a single stream of elements. It switches the inner publisher as new ones arrive but keeps the outer publisher constant for downstream subscribers. When this operator 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.

## See Also

### Republishing elements by subscribing to new publishers

- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-3k7z5.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-qxf.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-hyb0.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-4of8w.md)
- [switchToLatest()](combine/publisher/switchtolatest()-453ht.md)
- [switchToLatest()](combine/publisher/switchtolatest()-1c51y.md)
- [switchToLatest()](combine/publisher/switchtolatest()-20v3t.md)
