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

iOS Swift - Adding a Pop of Color - App Crashing/Simulator not Launching

When adding the View Controller (No) to the Info section and then the line of code:

application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)

The simulator does not open and I get the following error message:

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

Anyone know how to resolve this? I've tried resetting the simulator, but this doesn't appear to have rectified the issue.

The app was launching fine on the simulator before following the two steps above.

6 Answers

do you have any IBOutlet properties named funFact? if so, you most likely connected that funFact property from your storyboard to your Viewcontroller, then changed the name after it was already connected.

You will need to remove the connection, and reconnect it.

go to your view controller file and remove the line that has the IBOutlet declaration.

then go to your storyboard. select the control you are trying to reconnect. in the utilities panel, open up the outlets inspector (it has a little arrow icon thingy) and make sure the outlet connection is no longer there. if it is there, you can remove it (there should be a little x you can click)

once you are sure its no longer connected, open the assistant editor and control + click and drag from your storyboard to your view controller to reconnect the outlet. make sure you give it the same name as used in your code (probably funFact)

Thanks - that's allowed me to run the app now on the simulator without any error messages. I had changed the name of the IBOutlet after connecting it.

However, after making the changes, none of the functionality is working and the app now appears with two black strips at the top and bottom cutting off the screen, similar to how a film looks when it's in a widescreen format.

Any help is appreciated.

Cheers,

Tom

can you post a screen shot of what you see? also what was the outlet that you reconnected, was it a button? label?

Here's a link to the screenshot: http://s1061.photobucket.com/user/tom_barbour1/media/ScreenShot2014-12-19at182913_zps40c57169.png.html

It was a UIButton that I reconnected. I initially connected it via dragging to the assistant editor, I then changed the name of the button after dragging across. Following your steps seemed to resolve the issue, but now the app is unresponsive in the simulator, although I'm not getting any run errors in the logs.

Thanks,

Tom

you may need to reconnect the IBAction to your button as well then. open up your storyboard and open the assistant editor. in your view controller code, scroll down and find the buttons IBAction. in the gutter on the left side of the code editor (by the line numbers) there should be a little circle. click and drag (just regular click, not control click) from the little circle to the button and set it to be triggered on touch up inside.

that should make your app work, now we just need to figure out the black bars

Resetting the simulator seems to have got the app working now, although I still have the black cut off lines in the top and bottom margins.

do you still have a file called LaunchScreen.xib in your project?

also make sure in your project settings under app icons and launch images you have that file set to be the LaunchScreen

Thanks for that - followed the steps for reconnecting the IBAction to the button just before you posted and that seemed to get the button working again :)

Black bars still remain - not sure what's caused that :/

see my comment to your previous reply about the launch screen file

I'd deleted the launch screen in an attempt to rectify the button issue. I've restored it and linked back to LaunchScreen in the Custom Target Properties and that's resolved the issue :)

Thanks for your help!

cool glad its working now