Session 3

Let's Go to the Movies 🍿

Session Materials

Resources

Case Study Sign-Up

Find a partner for your case study presentation and decide what app you plan to discuss.

Here’s a list of open-source, app-store-ready iOS apps written in Swift.

Here’s a larger list of open-source iOS apps (please remember to only choose one that is both available in the app store and written in Swift)

Choose your presentation date here!.

Assignment

Submission link right here

In this assignment, you will create a application that allows users to view information about movies. We will use URLSession to fetch data from the iTunes Search API, and UITabBarController, UINavigationController, UITableViewController (or UIViewController with table view) to display it on screen.

Project Setup

Start with either the “Tabbed App” template or the “Single View App” template. Update the storyboard so that you have a UITabBarController with two tabs. Each tab should contain a UIViewController embedded in a UINavigationController. This will be an iPhone application that supports portrait mode only. When you’re done, your storyboard should look similar to the image below.

View Controllers

Tab Bar Controller

Table View Controllers

Tip: Remember to set the reuse identifier of each prototype cell.



Detail View Controller

So your storyboard will end up like this:

Auto Layout

Fetching Data

When each table view controller loads, query the iTunes API using the appropriate search term.

https://itunes.apple.com/search?country=US&media=movie&limit=20&term={your-search-term}

The Movie struct should contain the following properties:

    let trackName: String
    let primaryGenreName: String?
    let releaseDate: String?
    let contentAdvisoryRating: String?
    let longDescription: String?
    let previewUrl: String?
    let hasITunesExtras: Bool?
Tip: It's safe to assume that every movie object will have a trackName, but all other properties should be optional as they may not be present in the JSON.



Create a class called MovieService and add a function with this signature:

func search(for term: String, completion: @escaping ([Movie]?, Error?) -> ())

Use the code from the PodcastPicker app we reviewed in class to implement this function. You should only need to modify the url string and the Codable structs used to represent the data.

Add a movieService property to each table view controller. In viewDidLoad(), invoke the search function using the appropriate search term. Once the data is available, trigger a reload of your table by calling the table view’s reloadData() method.

Displaying Data

Tip: You will need to convert the `releaseDate` string into a `Date` object and then convert it back into a string to display it in the correct format.



You can display additional properties returned by the iTunes API if you choose.

Refactoring (Optional)

Extra Credit (10%)

App Icon

Grading

We will add your grade to your repository in a branch named “Grade.”