Async let explained: call async functions in parallel - SwiftLee

PHOTO EMBED

Sat Jul 09 2022 12:10:16 GMT+0000 (UTC)

Saved by @crsvld #swift

func loadImage(index: Int) async -> UIImage {
    let imageURL = URL(string: "https://picsum.photos/200/300")!
    let request = URLRequest(url: imageURL)
    let (data, _) = try! await URLSession.shared.data(for: request, delegate: nil)
    print("Finished loading image \(index)")
    return UIImage(data: data)!
}
content_copyCOPY

https://www.avanderlee.com/swift/async-let-asynchronous-functions-in-parallel/