To maintain a clear overview of the available API endpoints, you can add a nested enum to MovieDBHelper. Doing this will make other parts of the code more readable, help to avoid errors, and abstract away code duplication. An associated value will be used on the enum to hold onto the ID of a movie. This is quite convenient because the movie ID is part of the API endpoint.
Add the following code inside of the MovieDBHelper struct:
static let apiKey = "d9103bb7a17c9edde4471a317d298d7e" 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)") ...