Michael Long
1 min readOct 24, 2019

--

If, for example, your button press is triggering an API call on your singleton, then just store the resulting cancellable into a variable on your singleton. If the user hits the button again later on, just replace the old value and the prior cancellable will automatically deinit and cancel as needed.

That said, if said API call is using a Combine publisher on URLSession, in most cases the subscription is cancelled anyway as your API call has already returned its data AND completed.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet