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