Going over the basics
As a reactive framework, Combine is built upon components that publish updates (the publishers) and components that subscribe to updates (the subscribers).
In between, we’ve got the operators, which can manipulate data and control the stream flow. Let’s get an overview of Combine by starting with the publisher.
Starting with the publisher
The best way to explain how Combine works is by talking about publishers. Publishers are types that can deliver a sequence of values over time. We saw one example in Chapter 10:
URLSession.shared.dataTaskPublisher(for: url)
For a type to be a publisher, it needs to conform to the Publisher
protocol, and URLSession
is not the only type that does that. Timer
and NotificationCenter
are also types that have their publishers:
NotificationCenter.default.publisher(for: Notification.Name("DataValueChanged"))
Or, it can be a Timer
publisher:
let timerPublisher = Timer.publish(every...