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

Evgeny Nagimov
Evgeny Nagimov
4,075 Points

When I lunch the App it doesn't work and get this screen - http://screencast.com/t/YJYvLKMjnteP

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var funFuctLabel: UILabel!
    @IBOutlet weak var myFunFactButton: UIButton!

    let funFacts = FactModel()

    override func viewDidLoad() {
        super.viewDidLoad()
        funFuctLabel.text = funFacts.getRandomFact()
    }

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

    @IBAction func showFunFact() {
        let myRandomColor = ColorModel().getRandomColor()
        myFunFactButton.tintColor = myRandomColor
        view.backgroundColor = myRandomColor
        funFuctLabel.text = funFacts.getRandomFact()
    }
}

5 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

You probably had a disconnected outlet :P Next time just right click on the view controller to inspect your storyboard outlets. You won't have to rewrite your code.

Evgeny Nagimov
Evgeny Nagimov
4,075 Points

Everything is done as Pasan says.

Steven Deutsch
Steven Deutsch
21,046 Points

Can you post the top part of the debugger output for me? :P

Make sure all your @IBActions and @IBOutlets are hooked up properly. You can view them by right clicking on the yellow circle at the top of the view controller on the storyboard. You will see yellow caution indicators for warnings.

Evgeny Nagimov
Evgeny Nagimov
4,075 Points

2016-04-20 14:20:56.657 FunFacts[948:18067] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FunFacts.ViewController 0x7fac42e71bb0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key funFactButton.' *** First throw call stack: ( 0 CoreFoundation 0x0000000107f3cd85 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000109d2cdeb objc_exception_throw + 48 2 CoreFoundation 0x0000000107f3c9c9 -[NSException raise] + 9 3 Foundation 0x000000010830e19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x0000000108943d0c -[UIViewController setValue:forKey:] + 88 5 UIKit 0x0000000108b7a7fb -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x0000000107e76890 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit 0x0000000108b791de -[UINib instantiateWithOwner:options:] + 1864 8 UIKit 0x000000010894a8d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x000000010894b202 -[UIViewController loadView] + 178 10 UIKit 0x000000010894b560 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x000000010894bcd3 -[UIViewController view] + 27 12 UIKit 0x0000000108821fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x000000010882269d -[UIWindow _setHidden:forced:] + 282 14 UIKit 0x000000011e893d16 -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 68 15 UIKit 0x0000000108834180 -[UIWindow makeKeyAndVisible] + 42 16 UIKit 0x00000001087a8ed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 17 UIKit 0x00000001087af568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769 18 UIKit 0x00000001087ac714 -[UIApplication workspaceDidEndTransaction:] + 188 19 FrontBoardServices 0x000000010bc4c8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24 20 FrontBoardServices 0x000000010bc4c741 -[FBSSerialQueue performNext] + 178 21 FrontBoardServices 0x000000010bc4caca -[FBSSerialQueue _performNextFromRunLoopSource] + 45 22 CoreFoundation 0x0000000107e62301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION_ + 17 23 CoreFoundation 0x0000000107e5822c __CFRunLoopDoSources0 + 556 24 CoreFoundation 0x0000000107e576e3 __CFRunLoopRun + 867 25 CoreFoundation 0x0000000107e570f8 CFRunLoopRunSpecific + 488 26 UIKit 0x00000001087abf21 -[UIApplication _run] + 402 27 UIKit 0x00000001087b0f09 UIApplicationMain + 171 28 FunFacts 0x0000000107d54782 main + 114 29 libdyld.dylib 0x000000010a87f92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Steven Deutsch & Evgeny Nagimov: Yeah, Steven is right, that's a classic that is unfortunately quite cryptic and hard to debug. So if you ever experience the [ setValue:forUndefinedKey:]: exception after you rewired/deleted storyboard outlets, chances are you still have an outlet assigned to sthg. that is not there anymore. In storyboard, you can check the Connections inspector in the Utilities view. If there are any connections that should not be there, remove them.

Evgeny Nagimov
Evgeny Nagimov
4,075 Points

Hi! I don't know where was the problem, but I just re-wrote the App and it works now. Guess I did something wrong during the first attempt.

Thanks