IOS Development

Creating the tvOS film database utility with the assistance of The Film Database (TMDb) API

public class MovieStore: MovieService {

public static let sharing = MovieStore()

personal init()

personal let API key = "INSERT_API_KEY_HERE"

personal let baseAPIURL = "Https://api.themoviedb.org/three"

personal let urlSession = URLSession.sharing

personal let jsonDecoder: JSONDecoder = ()

public func search for motion pictures(of interval: Interval, params: [[[[Chain: Chain]? = nothingness, successHandler: @s & # 39; escape (_ reply: FilmsRéponse) -> Empty, errorHandler: @s & # 39; escape(_ Fault: Fault) -> Empty)

public func fetchMovie(login: Int, successHandler: @s & # 39; escape (_ reply: Film) -> Empty, errorHandler: @s & # 39; escape(_ Fault: Fault) -> Empty) {

hold let url = URLs(chain: "(baseAPIURL)/film/(login)? api_key =(API key)& append_to_response = movies, credit ") different

handleError(errorHandler: errorHandler, Fault: MovieError.invalidEndpoint)

return

urlSession.dataTask(with: url) (The information, reply, Fault) in

if Fault ! = nothingness

hold let httpResponse = reply as? HTTPURLResponse, 200..<300 ~= httpResponse.statusCode different

hold let The information = The information different

make

let film = strive self.jsonDecoder.decode(Film.self, of: The information)

DispatchQueue.main.async

successHandler(film)

seize

self.handleError(errorHandler: errorHandler, Fault: MovieError.serializationError)

.CV()

}

func searchMovie(query: Chain, params: [[[[Chain : Chain]?, successHandler: @s & # 39; escape (FilmsRéponse) -> Empty, errorHandler: @s & # 39; escape (Fault) -> Empty)

personal func handleError(errorHandler: @s & # 39; escape(_ Fault: Fault) -> Empty, Fault: Fault)

}