以下、参考にしたい新しいAPIのサンプルコードです。
// Fetch photo with async/await
func fetchPhoto(url: URL) async throws -> UIImage {
let (data, response) = try await URLSession.shared.data(from: url)
guard let httpResponse = response as? HTTPURLResponse,
httpResponse.statusCode == 200 else {
throw WoofError.invalidServerResponse
}
guard let image = UIImage(data: data) else {
throw WoofError.unsupportedImage
}
return image
}
時間の無駄なく将来のある王道な本筋のコードを吸収していきたいです。