Back to Swift Reference
⚡ ConcurrencyIntermediateSwift 5.5+ · iOS 13+

async / await

Write asynchronous code that reads top-to-bottom, with errors handled by normal try/catch.

An async function can suspend while it waits (for the network, disk, or another task) without blocking a thread. You call it with await.

Use async let to run independent work in parallel and await all results together.

async-await.swift
1struct Profile: Decodable { let name: String }
2struct Stats: Decodable { let followers: Int }
3
4func fetch<T: Decodable>(_ type: T.Type, from path: String) async throws -> T {
5    let url = URL(string: "https://api.example.com/\(path)")!
6    let (data, _) = try await URLSession.shared.data(from: url)
7    return try JSONDecoder().decode(T.self, from: data)
8}
9
10func loadDashboard() async throws -> (Profile, Stats) {
11    async let profile = fetch(Profile.self, from: "me")
12    async let stats = fetch(Stats.self, from: "me/stats")
13    return try await (profile, stats) // both requests run in parallel
14}

Common pitfalls

  • await does not mean "background thread" — isolation (actors, @MainActor) decides where code runs.

Still unclear? Ask BeeAI about async / await.

Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.

Ask BeeAI

Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.

See Pro Plans