From the course: Learning Combine with Swift

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Publish and subscribe to data with subjects

Publish and subscribe to data with subjects - Swift Tutorial

From the course: Learning Combine with Swift

Start my 1-month free trial

Publish and subscribe to data with subjects

- [Instructor] What is a publisher and the subscriber? Combine provides a special mechanism for publishing and subscribing using a single method called a subject, sounds intriguing. Let's explore further. A subject is considered a special type of publisher conforming to its own protocol, the subject protocol. Apple defines subjects as a publisher that exposes a method for outside callers to publish elements. And that's where the methods send comes in, enabling you to inject values into a stream. You would commonly use this approach to bridge existing imperative written code with the combined framework. Send is also invoked when one is broadcasting values to multiple subscribers connected to a subject. This is why subjects are often used to filter multiple publishers together or fan out as multiple publishers. A subject is an aggregator for subscribers to connect with publishers based on demand, so only subscribers that…

Contents