URLSession
internal extension URLSession
-
A generic method that decodes the response of a
URLSessionTask
Declaration
Swift
fileprivate func codableTask<T: Codable>(with url: URL, completionHandler: @escaping (T?, URLResponse?, Error?) -> Void) -> URLSessionDataTask
Parameters
url
The URL for the REST service to be requested
completionHandler
A completion handler to decode the response
-
A convenience method that builds a
URLSessionTask
to search for movies on themoviedb.orgDeclaration
Swift
func searchMoviesResponseTask(with url: URL, completionHandler: @escaping (SearchMoviesResponse?, URLResponse?, Error?) -> Void) -> URLSessionDataTask
Parameters
url
The URL for the REST service to be requested
completionHandler
A completion handler to decode the response
-
A convenience method that builds a
URLSessionTask
to download movie posters from themoviedb.orgDeclaration
Swift
func getMoviePosterTask(with url: URL, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask
Parameters
url
The URL for the REST service to be requested
completionHandler
A completion handler to handle the movie poster image
-
A convenience method to create a configured
JSONDecoder
for use with Decodable entitiesDeclaration
Swift
func newJSONDecoder() -> JSONDecoder