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 Improving Our User Interface Adding a Pop of Color

Michael O'Connor
Michael O'Connor
2,169 Points

App crashing on final steps of lesson

I was so close. I got the app running fine with the different facts randomly popping up and I even got the background colors to change. It was only the final few steps where I was synching the color of the text to match with that of the background that the app started to crash on me.

I attempted to backtrack, looked over everything and now I'm cross-eyed and confused as to what went wrong.

Here's the error message: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FunFacts.ViewController 0x7fef98453690> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tintColorChange.'


And here's my view controller: import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UILabel!
@IBOutlet weak var funFactButton: UIButton!

let factBook = FactBook()
let colorWheel = ColorWheel()

override func viewDidLoad() {
    super.viewDidLoad()
    funFactLabel.text = factBook.randomFact()
    // Do any additional setup after loading the view, typically from a nib.
}

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


@IBAction func showFunFact() {
    var randomColor = colorWheel.randomColor()
    view.backgroundColor = randomColor
    funFactButton.tintColor = randomColor
    funFactLabel.text = factBook.randomFact()

}

}

Anyone have any ideas?

1 Answer

Michael O'Connor
Michael O'Connor
2,169 Points

Never mind! Figured this out. As this problem seems to be plaguing a lot of other people, here's the video that gives you the solution: https://teamtreehouse.com/library/build-a-simple-iphone-app-with-swift/debugging-our-app/exception-breakpoints

If you don't want to sit through the video, here's what you need to do: go to the Connection Inspector, which is the icon to the right of the Attributes Inspector and Size Inspector that you've been using to modify the buttons and labels in your Storyboard. Work your way up through the different buttons and labels you've created. You'll notice that when you click on one of these buttons or labels, the Connection Inspector will show you all the connections that should link up to the code you've written in your View Controller.

Pull up the Assistant Editor and in the gutter along the left side of the numbers, you'll see dots that look like eyes. They will light up and indicate where the code in your View Controller matches with the button or label on your storyboard. If you have more connections in your Inspector than you do in your View Controller, than you have an extraneous connection that needs to get deleted from your Code Inspector. Click on the X to get rid of it.

If you're having trouble following this description, check out the video above. It will show you step-by-step what went wrong.