<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/AnyPublisher",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine12AnyPublisherV"
  },
  "title" : "AnyPublisher"
}
-->

# AnyPublisher

A publisher that performs type erasure by wrapping another publisher.

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

## Overview

[`AnyPublisher`](/documentation/Combine/AnyPublisher) is a concrete implementation of [`Publisher`](/documentation/Combine/Publisher) that has no significant properties of its own, and passes through elements and completion values from its upstream publisher.

Use [`AnyPublisher`](/documentation/Combine/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`](/documentation/Combine/Subject) with [`AnyPublisher`](/documentation/Combine/AnyPublisher) also prevents callers from accessing its [`send(_:)`](/documentation/Combine/Subject/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()`](/documentation/Combine/Publisher/eraseToAnyPublisher()) operator to wrap a publisher with [`AnyPublisher`](/documentation/Combine/AnyPublisher).

## Topics

### Creating a type-erased publisher

[`init(_:)`](/documentation/Combine/AnyPublisher/init(_:))

Creates a type-erasing publisher to wrap the provided publisher.

## Relationships

### Conforms To

[`Publisher`](/documentation/Combine/Publisher)

[`CustomPlaygroundDisplayConvertible`](/documentation/Swift/CustomPlaygroundDisplayConvertible)

[`Escapable`](/documentation/Swift/Escapable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Copyable`](/documentation/Swift/Copyable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)