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 Working With Multiple View Controllers Recap of iOS Basics

Josh Schlabach
Josh Schlabach
1,771 Points

App Crashes Immediately When Button Is Pressed

I followed everything that Pasan did in the video, and I get an error when I press the button. Anyone help?

Please share the code and the error.

Josh Schlabach
Josh Schlabach
1,771 Points

My code:

 <p> import UIKit

class ViewController: 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.

}

 @IBAction func buttonPressed() {
        view.backgroundColor = UIColor.orangeColor()
    }

} </p>



The error: (lldb)

1 Answer

fatal error: unexpectedly found nil while unwrapping an Optional value

remember optional String on that constructor