Chapter 11: SwiftUI Concurrency with async await
One of the most important features of Swift 5.5, released together with Xcode 13, is the introduction of the async
and await
keywords. With async
and await
, we can manage asynchronous concurrent code almost as if it was synchronous code.
Concurrency means that different pieces of code run at the same time. Often, we must orchestrate these pieces of code to create sequences of events to present the results in a view.
Before Swift 5.5, the most common way of creating a sequence of concurrent code was by using a completion block. When the first part of code finishes, we call a completion block where we start the second piece of code. This works and is manageable if we have only two asynchronous functions to synchronize. But it would become quickly unmaintainable with multiple functions and different ways of synchronizing them. For example, we could have two asynchronous functions to wait before starting the third one. With completion...