QUESTION OF THE WEEK
“
Is there a Combine alternative using Swift Concurrency?
Combine has not received many updates over the past years and it seems that Apple is slowly moving away from it too with the introduction of @Observable. Yet, there has not been an obvious replacement to observe values as we know from Combine.
There are ways to use AsyncStream to create a similar pipeline, but it comes with limitations like having only a single subscriber.
Apple's open-sourced Async Algorithms framework comes with methods you'll recognize from Combine pipelines, but it's the AsyncExtensions package that will give you classes like AsyncPassthroughSubject which will be closer to what you use in Combine.
I also want to highlight Swift Evolution Proposal SE-475: Transactional Observation of Values which is currently in Active Review. It's not a Combine replacement, but it will be a useful tool in case it gets implemented into a future version of Swift.
Finally, I've not found myself using Combine pipelines a lot lately. Debouncing and throtthling can be done via Swift Concurrency (learn about it here) and observing values is something I do using SwiftUI bindings. Whether these use Combine under the hood or not: I'll let Apple decide and make my code future proof.