Last active
September 29, 2022 21:19
-
-
Save jarrodnorwell/2760c57d760b85a90209c1b7a125d3d7 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
import Foundation | |
struct Movie : Codable, Hashable { | |
// ... | |
} | |
struct MovieResults : Codable, Hashable { | |
let results: [Movie] | |
} | |
enum TMDBAPIError : Error { | |
case invalidURL | |
} | |
class TDMBAPI { | |
static let shared = TMDBAPI() | |
func getPopularMovies() async throws -> [Movie] { | |
guard let url = URL(string: "...") else { | |
throw TMDBAPIError.invalidURL | |
} | |
let (data, _) = try await URLSession.shared.data(for: url) | |
return JSONDecoder().decode(MovieResults.self, from: data).results | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fairly sure MovieResults does not need to have Hashable however, I’ve added it anyway.