What is async/await

Asked on 06/16/2025

2 searches

Async/await is a feature in Swift that allows you to write asynchronous code in a more readable and maintainable way. It is part of Swift's concurrency model, which helps improve the responsiveness of applications by allowing certain operations to be performed without blocking the main thread.

Here's how it works:

  • Async Functions: A function that can be suspended and resumed later is marked with the async keyword. This indicates that the function contains operations that might take some time to complete, such as network requests or file I/O.

  • Await Keyword: When calling an async function, you use the await keyword. This marks a potential suspension point in your code, where the function might pause its execution to wait for the async operation to complete. During this suspension, other tasks can run, keeping the UI responsive.

  • Concurrency: By using async/await, you can break up your functions into parts that can run independently, allowing other work to be done while waiting for long-running operations to complete. This is particularly useful for tasks like fetching data over the network, where you don't want to block the main thread and cause the UI to freeze.

For more detailed information, you can refer to the session Embracing Swift concurrency (06:00) and Code-along: Elevate an app with Swift concurrency (03:42) from WWDC 2025.