Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aataraxiaa/c9dc24bf16c24c73486ec4918dc4686c to your computer and use it in GitHub Desktop.
Save aataraxiaa/c9dc24bf16c24c73486ec4918dc4686c to your computer and use it in GitHub Desktop.
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