Add Swift Concurrency (async/await) to 3rd party open-source projects

Marco Eidinger
2 min readJan 30, 2022

Is Swift Concurrency ready to adopt? Yes, because

Xcode 13.2 brings support for Swift Concurrency in applications that deploy to macOS Catalina 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes async/await, actors, global actors, structured concurrency, and the task APIs.

However, your project dependencies might not (yet) support async/await.

No problem, I will show you how to to apply the modern Swift Concurrency in such a scenario.

As an example, I use FeedKit. It’s an RSS, Atom and JSON Feed parser written in Swift.

It supports asynchronous processing by passing the results, once available, back to the caller through a completion handler.

FeedKit is a wonderful framework and works like a charm but it does not support async/await.

So let’s add an async function through a Swift extension 😊

The implementation uses a CheckedContinuation.

But how to create an async function that can fetch a dynamic number of feeds?

This function can run work in parallel thanks to Swift concurrency’s TaskGroup:

Done!

Here is a simplified example usable in a SwiftUI-based iOS application.

Originally published at https://blog.eidinger.info.

--

--

Marco Eidinger

Software Engineer open-source and enterprise mobile SDKs for iOS and macOS developers | @MarcoEidinger on Twitter | visit blog.eidinger.info