Avatar
@swift-main -Xfrontend -enable-experimental-concurrency import Foundation import FoundationNetworking struct User: Identifiable, Codable { typealias ID = Int let id: ID var name: String var thumbnailURL: URL } func download(from url: URL, completion: @escaping (Data) -> Void) { let data: Data = try! Data(contentsOf: url) completion(data) } func fetchUser(for id: User.ID, completion: @escaping (User) -> Void) { let url: URL = URL(string: "https://koherent.org/async-await-challenge/api/user?id=\(id.description)")! download(from: url) { data in let user = try! JSONDecoder().decode(User.self, from: data) completion(user) } } fetchUser(for: 123) { user in print(user.name) }