As a reactive programming framework, Combine enables various kinds of operations to be modeled as publishers that, when connected, can form asynchronous pipelines that let us process values and events through a series of stand-alone operators.
For example, a pipeline might start with a publisher that performs a network call to a given URL, which is then connected to operators that decode and cache the response of that network request, and finally the outcome of that entire pipeline is then observed in order to handle both successful and failed outcomes.
On this Discover page, you’ll find articles and podcast episodes that explore different aspects of Combine and how it can be used to solve real-world problems. We’ll also explore things like memory management, and how to unit test Combine-powered code.
It’s probably not a coincidence that Combine happened to be introduced at the exact same time as SwiftUI. While Combine can certainly also be used with both UIKit and AppKit, as well as within scripts and command line tools, its highly declarative design often makes it a perfect logic companion to SwiftUI-based views.
Here are a few ways to use Combine to drive and update a SwiftUI view’s state:
Since Combine is primarily geared toward handling asynchronous pipelines and operations, it’s very often a great match for networking code, which is something that typically involves a fair amount of steps that can be implemented using Combine’s various operators — especially since Foundation’s
URLSession API now ships with Combine support out of the box.
Starting with Swift 5.5, the language itself now has a native, built-in concurrency system that lets us perform various kinds of asynchronous operations without requiring any additional framework or abstractions. The good news is that it’s often possible (and sometimes quite simple, even) to mix Combine-based code with this new concurrency system. Here are a few ways to do just that:
The following articles explore some of the key convenience APIs that Combine ships with, which in many cases can enable us to build highly custom publishing logic without having to actually implement any custom
Publisher types from scratch. We’ll also take a look at how we can construct our own set of convenience APIs for specific use cases as well.
Next, let’s dive deeper into some of Combine’s more advanced aspects — which enable us to take complete control over how values are published, transformed, and merged.
The following articles contain tips and tricks on how to ensure that we won’t cause any memory leaks while setting up our Combine pipelines, as well as how to unit test Combine-based code:
Ever since its introduction in 2019, Combine has been a very commonly discussed topic on the podcast. These episodes are all particularly focused on Combine, with some of my friends from around the community sharing their tips on how they’re adopting Combine within their projects:
Donny Wals shares lots of tips on both Combine and Core Data
Daniel Steinberg on how Combine relates to functional programming
Marin Todorov on how Combine, SwiftUI and UIKit can all be used together
Casey Liss on how Combine compares to other reactive Swift frameworks, like RxSwift