Learn more about Combine

Using custom publishers to drive SwiftUI views

Updated on: September 30, 2020

In SwiftUI, views can be driven by an @Published property that’s part of an ObservableObject. If you’ve used SwiftUI and @Published before, following code should look somewhat familiar to you: class DataSource: ObservableObject { @Published var names = [String]() } struct NamesList: View { @ObservedObject var dataSource: DataSource var body: some View { List(dataSource.names, id: […]

Read post

Ignore first number of elements from a publisher in Combine

Published on: June 19, 2020

If you have a Combine publisher and you want to ignore the first n elements that are published by that publisher, you can use the dropFirst(_:) operator. This operator will swallow any values emitted until the threshold you specify is reached. For example, dropFirst(1) will ignore the first emitted value from a publisher: [1, 2, […]

Read post

Recursively execute a paginated network call with Combine

Published on: June 15, 2020

Last week, my attention was caught by a question that Dennis Parussini asked on Twitter. Dennis wanted to recursively make calls to a paginated API to load all pages of data before rendering UI. Since I love Combine and interesting problems I immediately started thinking about ways to achieve this using a nice, clean API. […]

Read post

Retrying a network request with a delay in Combine

Updated on: May 5, 2021

Combine comes with a handy retry operator that allows developers to retry an operation that failed. This is most typically used to retry a failed network request. As soon as the network request fails, the retry operator will resubscribe to the DataTaskPublisher, kicking off a new request hoping that the request will succeed this time. […]

Read post

Getting started with testing your Combine code

Published on: May 11, 2020

A question that often comes up when folks get into learning Combine is “how do I test code that uses Combine?”. In this week’s post, I will briefly explain the basics of testing Combine code. I will assume that you already know the basics of testing and Combine. If you’re just getting started with both […]

Read post

Changing a publisher’s Failure type in Combine

Published on: April 15, 2020

One of Combine’s somewhat painful to work with features is its error mechanism. In Combine, publishers have an Output type and a Failure type. The Output represents the values that a publisher can emit, the Failure represents the errors that a publisher can emit. This is really convenient because you know exactly what to expect […]

Read post

Profiling and debugging your Combine code with Timelane

Published on: March 16, 2020

When we write code, we write bugs. It’s one of the laws of the universe that we can’t seem to escape. The tools we have to discover, analyze and fix these bugs are extremely important because without good debugging tools we’d be poking at a black box until we kind of figure out what might […]

Read post

Expand your learning with my books

Practical Combine header image

Learn everything you need to know about Combine and how you can use it in your projects with Practical Combine. It contains:

  • Thirteen chapters worth of content.
  • Playgrounds and sample projects that use the code shown in the chapters.
  • Free updates for future iOS versions.

The book is available as a digital download for just $39.99!

Learn more