CancelBag

public final class CancelBag

A container for managing a collection of cancellable objects.

  • Initializes a new instance of CancelBag.

    Declaration

    Swift

    public init()
  • Cancels all subscriptions in the cancel bag.

    Declaration

    Swift

    public func cancel()
  • Collects the given cancellable objects and adds them to the cancel bag.

    The collect function is a convenient way to add multiple cancellable objects to the cancel bag at once. It utilizes the @Builder attribute to aggregate multiple AnyCancellable instances into an array. The closure passed to collect is a builder closure that can use multiple lines to define the cancellable objects, and each line creates a separate AnyCancellable instance. This simplifies the process of adding multiple cancellables to the cancel bag in a more readable and expressive manner.

    Declaration

    Swift

    public func collect(@CancelBag.Builder _ cancellables: () -> [AnyCancellable])

    Parameters

    cancellables

    A closure returning an array of cancellable objects.

  • A result builder for aggregating multiple cancellable objects.

    See more

    Declaration

    Swift

    @resultBuilder
    public enum Builder