O'Reilly logo

Mastering iOS 11 Programming - Second Edition by Donny Wals

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preparing the helper struct

In order to maintain a clear overview of the available API endpoints, we will add a nested enum to the MovieDBHelper. Doing this will make other parts of our code more readable, and we can avoid errors and abstract away duplication with this enum. We'll make use of an associated value on the enum to hold on to the ID of a movie; this is convenient because the movie ID is part of the API endpoint.

Add the following code inside of the MovieDBHelper struct:

static let apiKey = "YOUR_API_KEY_HERE" enum Endpoint {     case search     case movieById(Int64)     var urlString: String {         let baseUrl = "https://api.themoviedb.org/3/"         switch self {         case .search:             var urlString = "\(baseUrl)search/movie/"  urlString = urlString.appending("?api_key=\(MovieDBHelper.apiKey)") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required