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 Simple iPhone App with Swift 2.0 Improving Our User Interface Adding a Pop of Color

Anna Benson
Anna Benson
2,728 Points

Trouble running "FunFacts" app on simulator

I have been beginning to build the "FunFacts" app, and every time that I have tried to run the simulation and I press the "show me another fun fact" button, instead of showing another fun fact or changing the background color, it closes out of the simulator and shows the code in the debug area.

Is there something wrong in my View Controller that is causing this? I've copypasted my code below:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UILabel!
let factModel = FactModel()

override func viewDidLoad() {
    super.viewDidLoad()
    funFactLabel.text = factModel.getRandomFact()
}

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

@IBAction func showFunFact() {
    let newColor = UIColor (red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0)
    view.backgroundColor = newColor
    funFactLabel.text = factModel.getRandomFact()
}

}

1 Answer

Reed Carson
Reed Carson
8,306 Points

when the compiler does that it means its crashing. if it does that when you click on the button its probably because it found a nil value for a non optional type, or you might have a broken connection for a storyboard element. in the debug window on the bottom right will be a bunch of gibberish but if you look through it closely you should be able to see a reference to the object the compiler has a problem with, so youll know which part to look at.