Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Playlist Browser with Swift Using a Navigation Controller With Segues Passing Information Between Views

Anish Patel
Anish Patel
5,537 Points

Help! I don't know why my app keeps crashing.

Here is my code: There is an error which says to put an ! after the as but i have tried this and it does not work, could someone please tell me what is wrong.

//PlaylistMasterViewController 

import UIKit

class PlaylistMasterViewController: UIViewController {

    @IBOutlet weak var buttonPressLabel: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

    buttonPressLabel.setTitle("Press Me", forState: .Normal)


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showPlaylistDetail" {
            let playlistDetailController = segue.destinationViewController as
                PlaylistDetailViewController
            playlistDetailController.segueLabelText = "Yay you pressed the button"

        }

    }

}

//PlaylistDetailViewController 

import UIKit

class PlaylistDetailViewController: UIViewController {

    @IBOutlet weak var aButton: UILabel!
    var segueLabelText: String = ""


    override func viewDidLoad() {
        super.viewDidLoad()

        aButton.text = segueLabelText

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Anish,

Not sure either - your code looks fine. I would check in the storyboard that your destination view controller is properly identified as a PlaylistDetailViewController. Click on that view controller, and look in the identity inspector to see if you've identified it as such. That'd be my first place to check.

Cheers :beers:

-Greg