Lesson 5 Code Reference Sheet

This outline is intended as a quick way to reference code snippets from this lesson. It includes any code you were expected to write yourself and git branch names for code provided for you.

MYOA Steps and Solution

To see a sample Make Your Own Adventure project, checkout step5.1-makeYourOwnAdventure

Adding “Start Over” button: Step 1

Add the Start Over button to the nav bar:

override func viewDidLoad() {
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start Over", style: UIBarButtonItemStyle.Plain, target: self, action: "startOver")

Adding “Start Over” button: Step 2

The startOver() method:

func startOver() {
    if let navigationController = self.navigationController? {

“Start Over” Button, Steps and Solution

To see the start over button implemented checkout step5.2-makeYourOwnAdventure-startOver

Replacing Rock, Paper, and Scissors logic with navigation

To start the Rock Paper Scissors with Navigation checkout step5.3-rockPaperScissors

RPS with Navigation: Solution

To see the RockPaperScissors app implemented with navigation checkout the branch step5.4-rockPaperScissors-withNavigation

Master Detail: Navigation for Tables

Code to push the detail view controller:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let storyboard = self.storyboard!
    let detailController = storyboard.instantiateViewControllerWithIdentifier
    ("VillainDetailViewController") as! VillainDetailViewController
    detailController.villain = self.allVillains[indexPath.row]
    self.navigationController!.pushViewController(detailController, animated: true)

Steps to rebuild Bond Villains

Notes on the Challenge App