Storyboard Actors Project

Implementing the Actors app in SwiftUI

In this exercise you are going to convert a portion of the Actors app to SwiftUI. Start by clicking the button above to download the project for the Storyboard version of the Actors app. In this assignment you are going to write a SwiftUI app that allows uses to search for movies and series, view a list of actors in a given title, and then view details about each actor. For this assignment you will not need to implement the favorites feature from the original app: you will not need to have a favorite button on the actor detail page, you will not need a view that displays the list of favorites, and you will not need a tab view to help you switch to the list of favorites.

Before starting work on the new app you will need to register to get an API key for the web service we are using. Go to imdb-api.com and click the Register button to sign up for a free account. In various places in my code you will see a statement that looks like

let key = "<Your key here>"

You will need to paste your API key in those places.

Helpful hints

The original Storyboard app used a somewhat complex and unweildy strategy to manage its data. If you look in the Series.swift file you will see a collection of structure definitions. These are structures used to represent the data that comes back from the web service when the app makes various queries. Right now the Actors app uses that data and stores in various views along the way as it does those queries.

You may want to change the way that the app stores all of those search results. Specifically, you will want to create a single model class that can store all of those search results for you. That model class would store:

Here are some additional suggestions on how to use this model class.

When the user clicks the search button in the first view you will call a method in the model class that sends the search to the server. When the results from that search come back you will put those results in an array of SearchResult objects in the model object. You should mark that array @Published so the view knows it needs to rebuild its list of search results.

In the code that builds the list of search results in the first view you need to add an onTapGesture modifier. The code in the closure for that modifier should tell the model class to remember the search result the user clicked on and then trigger the NavigationLink that takes you to the second view.

You should attach a Task modifier to the second view. The closure for that task will tell the model object to fetch the SeriesData for the currently selected SearchResult. The property that the model uses to store the SeriesData that comes back from that query should also be marked @Published, because the second view will be using that SeriesData object to display its information about the show. When that property changes the second view will know that it will need to rebuild itself and display the information that is in that SeriesData object.

The second view will display a list of actors for the show the user selected. Once again in the code that builds the list that displays that data you need to attach an onTapGesture handler that tells the model object to use the actor the user clicked on and then triggers the navigation link that takes the user to the third view.

Finally, you will need to know how to display the actor's picture in the third view. SwiftUI now offers a convenient AsyncImage object that makes it easier to load an image from a URL. You can find documenation on AsyncImage here.