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 Modifying the UI

Andrew Bauml
Andrew Bauml
2,181 Points

While the update of Xcode requires ! or ? for downcasting, why do I still get a fatal error?

I've done the fix-it to add an "!" to "as", made sure that the UILabel is referenced to artists, and it still says that it unwraps nil. This is the error; fatal error: unexpectedly found nil while unwrapping an Optional value Printing description of playlistDetailController: (Algorhythm.PlaylistDetailViewController?) playlistDetailController = 0x00007fb6cb725800 { UIKit.UIViewController = { UIKit.UIResponder = { ObjectiveC.NSObject = {} } } buttonPressLabel = nil segueLabelText = "" }

//and stops at

segue UIStoryboardSegue 0x00007fb6cb718010 0x00007fb6cb718010 sender AnyObject? Some Some self Algorhythm.PlaylistMasterViewController 0x00007fb6cb42f740 0x00007fb6cb42f740 playlistDetailController Algorhythm.PlaylistDetailViewController? 0x00007fb6cb725800 0x00007fb6cb725800

Thank you for any help!

11 Answers

Polidoros Karampougikis
Polidoros Karampougikis
1,820 Points

For those who still get errors check once again the IBOutlet of the label, if it is correctly connected.

Polidoros.. I have checked many times.

Can you have a look at my code for me?

import UIKit

class PlaylistMasterViewController: UIViewController {

    @IBOutlet weak var aButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        aButton.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."
        }
    }
}
import UIKit

class PlaylistDetailViewController: UIViewController {

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

    override func viewDidLoad() {
        super.viewDidLoad()

        buttonPressLabel.text = segueLabelText
    }

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

}

thank you

Polidoros Karampougikis
Polidoros Karampougikis
1,820 Points

Thomas your code looks fine to me, i used the same exact code, the problem was that when i right clicked on the label, i noticed that there was no IBOutlet connected, So i deleted the @IBOutlet weak var buttonPressLabel: UILabel! and re-connected it using the control drag option. If it isn't your label, check your button then, something isn't correctly mentioned in the code.

Polidoros Karampougikis i reconnected the button, and yaay it worked. Atleast now it's not giving me an error when i run the app. Now it just shows both the "yay, you have pressed the button" and the "you haven't pressed the button". And it's not overwriteing:S

Polidoros Karampougikis
Polidoros Karampougikis
1,820 Points

Thomas, try deleting the IBOutlet of the Label and the Label itself and drag a new one in the middle and reconnect it like you did in the tutorial.

I did sir. But dont know what is wrong, I think i will do the course over again to get it right and get some more learning. Thanks, and heres an upvote

Andrew Baumi, can you tell me what the problem was? I simply can't figure it out, and now i've seen the clip 3 times and all my code matches.

Jiasheng Qu
Jiasheng Qu
1,959 Points

I got the same problem. But once I change my code to

playListDetailController.segueLabelText = "Yay!You Pressed the button."

then it became fine.

Hi Jiasheng Qu

I still have the error. When i launch the APP and press the button, it says that there is an error in the code:

let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController

Can you please send me your code, so that I can compare?

Greetings

Andrew Bauml
Andrew Bauml
2,181 Points

Hey Thomas, sorry it took so long to get back to you. My issue was that in the playlistMasterVC I had playlistDetailViewController.buttonLabelPress.txt = "Yay! You pressed the button!" and needed playlistDetailController.segueLabelText = "Yay! You pressed the button!"

It looks like you might have an extra curly brace at the bottom of your PlaylistMasterViewController

Hi Andrew Bauml. If I remove one of my curlybracers it gives me and error. Would you mind to show me all of your code?

Tanks for the response :)

I need help! My partner and I have been reading all of your revisions, and they don't seem to work. Here is our code.

// // ViewController.swift // Algorhythm // // Created by Michela Burns on 7/28/15. // Copyright (c) 2015 Michela Burns and Kai Wong. All rights reserved. //

import UIKit

class PlaylistMasterViewController: UIViewController { @IBOutlet weak var buttonPressLabel:UILabel! var segueLabelText: String = ""

@IBOutlet weak var aButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

 aButton.setTitle("Press me!", forState: .Normal)
    //buttonPressLabel.text=segueLabelText
}

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.buttonPressLabel.text = "Yay! You pressed the button!";
    }

   }

}

// // PlaylistDetailViewController.swift // Algorhythm // // Created by Michela Burns on 7/28/15. // Copyright (c) 2015 Michela Burns and Kai Wong. All rights reserved. //

import UIKit

class PlaylistDetailViewController: UIViewController {

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

override func viewDidLoad() {
    super.viewDidLoad()

    buttonPressLabel.text = segueLabelText


}

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

}

Can I get a look at the code itself? Did you implement a nil check if you get back some bad/nil data?

Andrew Bauml
Andrew Bauml
2,181 Points

//MasterView import UIKit

class PlaylistMasterViewController: UIViewController {

@IBOutlet weak var aButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

aButton.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.buttonPressLabel.text = "Yay, you pressed the button":

//DetailView

import UIKit

class PlaylistDetailViewController: UIViewController {

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

override func viewDidLoad() {
    super.viewDidLoad()

  buttonPressLabel.text = segueLabelText
}

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

}

Thank you Marlon

Can you please help me out? I am also facing the same problem. thanks in advance

What's the else part of the statement? So far I'm not seeing a issue

I had the same issue where the fix it was to add an !, but after I did that the issue was resolved and everything seems to work normally. My code is identical to yours though, so I am not sure what your bug is.

Kenton Raiford
Kenton Raiford
5,101 Points

I have the same issue and I added the ! but my code still isn't working. Did you fix it?

Andrew Bauml
Andrew Bauml
2,181 Points

Yes, watch the video very closely. There's one part that I had missed about rewriting something on the playlistDetailController. Good luck, you'll laugh when you realize how blatant it was!

Kenton Raiford
Kenton Raiford
5,101 Points

I did everything he said in the video and my app is still crashing when I click the button.

did you fix your problem? I am also facing the same problem.

did you fix your problem? I am also facing the same problem.