Integrate Combine Into an App

Aug 5 2021 · Swift 5.4, macOS 11.3, Xcode 12.5

Part 1: Define a View Model

01. Identify Where to Use Combine

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Next episode: 02. Use @Published to Publish State

Notes: 01. Identify Where to Use Combine

Check out our Reactive Programming in iOS with Combine and Intermediate Combine courses to brush up on the skills you’ll need for this course. This course is based on the “Combine: Asychronous Programming with Swift” book from!

Transcript: 01. Identify Where to Use Combine

If you’ve read tutorials or watched other videos about Combine, you’ve probably learned lots of distinct sets of information. But concepts don’t live in isolation - they have to be applied to an app. I happen to have here the next best selling app destined for the App Store - one that delivers Chuck Norris style jokes. Here’s a sneak preview of some of the features.

The user can swipe left to say you don’t like the joke, or right to indicate you’ll remember this one for your next ice breaker at work. If the joke is not liked, it will turn red; otherwise it will turn green.

The user can save jokes. The app will Automatically fetch a new joke, and show an indicator. The app will display appropriate error messages. The user can toggle between English and Spanish versions of the jokes. The user can view their saved jokes. The user can delete saved jokes.

I’ve identified quite a few areas where I could use Combine in the app. They are

Defining a view model. SwiftUI natively uses Combine to keep your back end data and values displayed in the user interface in sync - but first we need to define a model that will hold those values.

Once we have that ViewModel in place, we can tie it into SwiftUI using built-in property wrappers.

The user will be able to save their favorite jokes, and that will happen by way of a Core Data database. Here, Combine will allow the user interface and the database to stay in sync as values are added or deleted.

Finally, testing is vital in any app, and the Given-When-Then pattern can be used to test your code - including your Combine pipeline code. Using Combine in these areas should give our app the Chuck Norris style punch it needs.

This course is based off the Combine: Asynchronous Programming with Swift book from - if you like what you see here and want to learn more, please check it out.