Last active
July 16, 2021 14:09
-
-
Save aataraxiaa/c9dc24bf16c24c73486ec4918dc4686c to your computer and use it in GitHub Desktop.
This file contains 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
func fetchData(from url: URL) async throws -> ModelWrapper { | |
let (data, _) = try await URLSession.shared.data(from: url) | |
let model = try JSONDecoder().decode(Model.self, from: data) | |
let (imageData, _) = try await URLSession.shared.data(from: model.imageURL) | |
guard let image = UIImage(data: imageData) else { | |
throw APIErrors.imageDecodingError | |
} | |
return ModelWrapper(model: model, image: image) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment