Created
May 10, 2022 19:33
-
-
Save aliakhtar49/5ae83204e8109ca9d76b9780fdfcdfd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let metadataUrl = URL(string: "https://www.andyibanez.com/fairesepages.github.io/tutorials/async-await/part1/\(imageNumber).json")! | |
let metadataTask = URLSession.shared.dataTask(with: metadataUrl) { data, response, error in | |
guard let data = data, let metadata = try? JSONDecoder().decode(ImageMetadata.self, from: data), (response as? HTTPURLResponse)?.statusCode == 200 else { | |
completionHandler(nil, ImageDownloadError.invalidMetadata) | |
return | |
} | |
let detailedImage = DetailedImage(image: image, metadata: metadata) | |
completionHandler(detailedImage, nil) | |
} | |
metadataTask.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment