One Logo Pool Ball
Combine · IOS API REFERENCE

AnyCancellable

class · iOS 13.0+ · SDK 27.1

final class AnyCancellable

A type-erasing cancellable object that executes a provided closure when canceled. 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 ``Cancellable/cancel()`` when deinitialized.

Members (5)

method · iOS 13.0+

store

TypeScript
storeIn(set: Array<AnyCancellable>): { $ret: null; $out: { "set": Array<AnyCancellable> } }
Swift declaration
final func store(in set: inout Set<AnyCancellable>)

Stores this type-erasing cancellable instance in the specified set. - Parameter set: The set in which to store this ``AnyCancellable``.

Omit the output parameters from the call. The result contains $ret and $out, with set inside $out.

method · iOS 13.0+

store

TypeScript
storeIn88072(collection: Array<AnyCancellable>): { $ret: null; $out: { "collection": Array<AnyCancellable> } }
Swift declaration
final func store<C>(in collection: inout C) where C : RangeReplaceableCollection, C.Element == AnyCancellable

Stores this type-erasing cancellable instance in the specified collection. - Parameter collection: The collection in which to store this ``AnyCancellable``.

Omit the output parameters from the call. The result contains $ret and $out, with collection inside $out.

method · iOS 13.0+

cancel

TypeScript
cancel(): void
Swift declaration
final func cancel()

Cancel the activity. When implementing ``Cancellable`` in support of a custom publisher, implement `cancel()` to request that your publisher stop calling its downstream subscribers. Combine doesn't require that the publisher stop immediately, but the `cancel()` call should take effect quickly. Canceling should also eliminate any strong references it currently holds. After you receive one call to `cancel()`, subsequent calls shouldn't do anything. Additionally, your implementation must be thread-safe, and it shouldn't block the caller. > Tip: Keep in mind that your `cancel()` may execute concurrently with another call to `cancel()` --- including the scenario where an ``AnyCancellable`` is deallocating --- or to ``Subscription/request(_:)``.

init · iOS 13.0+

init

TypeScript
static init(canceller: AnyCancellable): AnyCancellable
Swift declaration
init<C>(_ canceller: C) where C : Cancellable
init · iOS 13.0+

init

TypeScript
static init89168(cancel: (() => void)): AnyCancellable
Swift declaration
init(_ cancel: @escaping () -> Void)

Initializes the cancellable object with the given cancel-time closure. - Parameter cancel: A closure that the `cancel()` method executes.

Skipped declarations

No declarations were skipped in this snapshot.

All Combine types →