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 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