---
title: AnyCancellable
framework: combine
role: symbol
role_heading: Class
path: combine/anycancellable
---

# AnyCancellable

A type-erasing cancellable object that executes a provided closure when canceled.

## Declaration

```swift
final class AnyCancellable
```

## Mentioned in

Controlling Publishing with Connectable Publishers

## Overview

Overview Subscriber implementations can use this type to provide a “cancellation token” that makes it possible for a caller to cancel a publisher, but not to use the Subscription object to request items. An AnyCancellable instance automatically calls cancel() when deinitialized.

## Topics

### Creating a type-erased cancellable

- [init(_:)](combine/anycancellable/init(_:)-3icn3.md)
- [init(_:)](combine/anycancellable/init(_:)-48fh3.md)

### Storing instances

- [store(in:)](combine/anycancellable/store(in:)-6cr9i.md)
- [store(in:)](combine/anycancellable/store(in:)-3hyxs.md)

### Operators

- [==(_:_:)](combine/anycancellable/==(_:_:).md)

## Relationships

### Conforms To

- [Cancellable](combine/cancellable.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)

## See Also

### Publishers

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