Cancelling Subscriptions in Combine Illustrated using SwiftUI

A look at how to use subscriptions in Combine work

Mark Lucking
Geek Culture

--

Subscribers are the lifeblood of business models around the world, indeed they are the way things seem to be going when it comes to buying software these days. And we already have them in Swift with in-app purchases a subject I wrote about in this paper.

So, it seems fitting that they're moving into mainstream software engineering within it too. Subscriptions a major component of the new Combine Framework. Join me on an exploration of how a major component/aspect of them works. Cancellation.

Now the Combine framework has three principal players — The Publishers, the Subscribers, and the Operators. The principle on which they work is much like the UNIX shell really, with the concept that you pipe data from one operation to another transforming it as you do.

The Brief

You’re building a control panel for a space game and you want some sort of indicator that everything is running smoothly. You opt for two orange flashing dots. You need two buttons, one to turn them on; one to turn them off.

--

--

Mark Lucking
Geek Culture

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More