Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Playlist Browser with Swift Using a Navigation Controller With Segues Modifying the UI

fatal error: unexpectedly found nil while unwrapping an Optional value

Getting error on this line: buttonPressedLabel.text = segueLabelText

I tried writing the code myself as well as running the provided xcode project files, I'm still getting the error. Just for funsies I deleted the label and created a new one, still getting the error.

Any help would be greatly appreciated.

3 Answers

Do you have segueLabelText set to an empty string

import UIKit

class PlaylistDetailViewController: UIViewController {

    @IBOutlet weak var buttonPressLabel: UILabel!
    var segueLabelText: String = ""
    //rest of code .................    
Iván Jesús Fanjul Cosént
Iván Jesús Fanjul Cosént
3,882 Points

Hello Sean,

here i got the same problem, but taking a look for a while I just found that for some reason my buttonPressedLabel just lost the reference to the outlet.

If you go to your Main.storyboard and click the label in the Artist Scene and click on the Show Connectors inspector, you are going to notice that there is no reference to your label.

As you can see I just made a test code like this: added a new reference to the label, and tried it again


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

@IBOutlet weak var test: UILabel!

override func viewDidLoad() {

    // Do any additional setup after loading the view.

   // buttonPressLabel.text = segueLabelText
    test.text = segueLabelText  


It works for me, now i just need to delete the old reference and the text one and add it again . Hope this helps

Iván Jesús Fanjul Cosént
Iván Jesús Fanjul Cosént
3,882 Points

(Sorry me, i don't know how to post swift code, any example would be apreciated)

I had the same problem and fixed it my creating a new outlet for the label.