Swift 6 · Errors and concurrency

Async functions

async functions can suspend. Call them with await.

func fetchUser() async throws -> User {
    let (data, _) = try await URLSession.shared.data(from: url)
    return try JSONDecoder().decode(User.self, from: data)
}

Official Swift 6 documentation

More errors and concurrency commands

All errors and concurrency commands · Swift 6 cheatsheet

Was this page helpful?