Customize handling of asynchronous events by combining event-processing operators.
SDKs
- iOS 13.0+Beta
- macOS 10.15+Beta
- UIKit for Mac 13.0+Beta
- tvOS 13.0+Beta
- watchOS 6.0+Beta
Overview
The Combine framework provides a declarative Swift API for processing values over time. These values can represent user interface events, network responses, scheduled events, and many other kinds of asynchronous data. Combine declares publishers to expose values that can change over time, and subscribers to receive those values from the publishers.
The
Publisherprotocol declares a type that can deliver a sequence of values over time. Publishers have operators to act on the values received from upstream publishers and republish them.At the end of a chain of publishers, a
Subscriberacts on elements as it receives them. Publishers only emit values when explicitly requested to do so by subscribers. This puts your subscriber code in control of how fast it receives events from the publishers it’s connected to.
By adopting Combine, you’ll make your code easier to read and maintain, by centralizing your event-processing code and eliminating troublesome techniques like nested closures and convention-based callbacks.