---
title: AnyPublisher
framework: combine
role: symbol
role_heading: Structure
path: combine/anypublisher
---

# AnyPublisher

A publisher that performs type erasure by wrapping another publisher.

## Declaration

```swift
@frozen struct AnyPublisher<Output, Failure> where Failure : Error
```

## Mentioned in

Using Combine for Your App’s Asynchronous Code

## Overview

Overview AnyPublisher is a concrete implementation of Publisher that has no significant properties of its own, and passes through elements and completion values from its upstream publisher. Use AnyPublisher to wrap a publisher whose type has details you don’t want to expose across API boundaries, such as different modules. Wrapping a Subject with AnyPublisher also prevents callers from accessing its send(_:) method. When you use type erasure this way, you can change the underlying publisher implementation over time without affecting existing clients. You can use Combine’s eraseToAnyPublisher() operator to wrap a publisher with AnyPublisher.

## Topics

### Creating a type-erased publisher

- [init(_:)](combine/anypublisher/init(_:).md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomPlaygroundDisplayConvertible](swift/customplaygrounddisplayconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)
- [Publisher](combine/publisher.md)

## See Also

### Publishers

- [Publisher](combine/publisher.md)
- [Publishers](combine/publishers.md)
- [Published](combine/published.md)
- [Cancellable](combine/cancellable.md)
- [AnyCancellable](combine/anycancellable.md)
