Async/Await in Swift

From the Swift cheat sheet · Concurrency · verified Jul 2026

Async/Await

Modern Swift concurrency

swift
// Async function
func fetchUserData() async -> User {
    // Simulated network call
    try? await Task.sleep(for: .seconds(1))  // 1 second
    return User(name: "John")
}

// Calling async function
Task {
    let user = await fetchUserData()
    print("User: \(user.name)")
}

// Async throwing function
func downloadFile(from url: URL) async throws -> Data {
    let (data, _) = try await URLSession.shared.data(from: url)
    return data
}

// Async let for concurrent execution
async let user = fetchUserData()
async let posts = fetchPosts()
let profile = await Profile(user: user, posts: posts)
💡 async/await makes asynchronous code look synchronous
⚡ async let enables parallel execution
📌 Task groups handle dynamic concurrency
🟢 @MainActor ensures UI updates on main thread

More Swift tasks

Back to the full Swift cheat sheet