Table of Contents
Despite all the tools, writing code that is executed in parallel on different threads is still not trivial and harbors a great potential for errors. The Swift programming language from Apple for developing apps for iOS and Co. is no exception in this regard. In fact, Swift did not come with any mechanisms of its own to run code in parallel until version 5.5, which was released in September 2021. Instead, the dispatch framework was used, which contains various types and functions for this purpose that perform various actions at the same time.
This three-part tutorial covers Swift’s new concurrency model introduced in the current version 5.5 of the programming language. This first article is about the keywords async
and await
the new syntax async let
and task groups.
More about mobile software development
So far, concurrency in Swift has mainly been achieved using escaping closures. A function running in parallel received a closure as a parameter that was called as soon as the function had processed all actions. This concept entails two problems: On the one hand, the clarity suffers with nested calls in which several closures are used one after the other. The sequence of the processed commands is also difficult to understand in more complex constructs.
- Access to all content from heise+
- exclusive tests, guides & backgrounds: independent, critically well-founded
- Read c’t, iX, MIT Technology Review, Mac & i, Make, c’t photography directly in your browser
- Register once – read on all devices – can be canceled monthly
- first month free, then monthly from €9.95
- Weekly newsletter with personal reading recommendations from the editor-in-chief
Start FREE month
Start your FREE month now
already subscribed to heise+?
Sign up and read
Register now and read the article immediately
More information about heise+