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.
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, a quick message from this week’s sponsor
Swift by Sundell is completely free for everyone, but if you’d like to support my work, then please take just a few minutes to check out the following sponsor, since doing so really helps me out financially.
Building Mobile Apps at Scale: Based on learnings from scaling the development of the Uber app over four years — this free, 200-page book will help you overcome 39 of the most commonly faced challenges when building large iOS apps. The book is free to download for a limited time, so grab your copy now.
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