A protocol that declares a type that can receive input from a publisher.
- iOS 13.0+Beta
- macOS 10.15+Beta
- tvOS 13.0+Beta
- watchOS 6.0+Beta
- Xcode 11.0+Beta
- Mac Catalyst 13.0+Beta
Subscriber instance receives a stream of elements from a
Publisher, along with life cycle events describing changes to their relationship. A given subscriber’s
Failure associated types must match the
Failure of its corresponding publisher.
You connect a subscriber to a publisher by calling the publisher’s
subscribe(_:) method. After making this call, the publisher invokes the subscriber’s
receive(subscription:) method. This gives the subscriber a
Subscription instance, which it uses to demand elements from the publisher, and to optionally cancel the subscription. After the subscriber makes an initial demand, the publisher calls
receive(_:), possibly asynchronously, to deliver newly-published elements. If the publisher stops publishing, it calls
receive(completion:), using a parameter of type
Subscribers to indicate whether publishing completes normally or with an error.
Combine provides the following subscribers as operators on the
sink(receiveCompletion:receiveValue:) executes arbitrary closures when it receives a completion signal and each time it receives a new element.
assign(to:writes each newly-received value to a property identified by a key path on a given instance.