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

Terminating app due to uncaught exception 'NSUnknownKeyException'

I'm getting a strange error when I start my iOS Simulator for my app in XCode. It just stays stuck at the launch screen and I get an error at the bottom that looks like this:

2014-11-01 19:35:06.021 Juxta[20715:347104] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Juxta.ViewController 0x7ff280c84650> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key voteCount1.' *** First throw call stack: ( 0 CoreFoundation 0x000000010aa513f5 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010c57fbb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010aa51039 -[NSException raise] + 9 3 Foundation 0x000000010ae684d3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259 4 CoreFoundation 0x000000010a99b400 -[NSArray makeObjectsPerformSelector:] + 224 5 UIKit 0x000000010b59e97d -[UINib instantiateWithOwner:options:] + 1506 6 UIKit 0x000000010b3ff698 -[UIViewController _loadViewFromNibNamed:bundle:] + 242 7 UIKit 0x000000010b3ffc88 -[UIViewController loadView] + 109 8 UIKit 0x000000010b3ffef9 -[UIViewController loadViewIfRequired] + 75 9 UIKit 0x000000010b40038e -[UIViewController view] + 27 10 UIKit 0x000000010b31fdb9 -[UIWindow addRootViewControllerViewIfPossible] + 58 11 UIKit 0x000000010b320152 -[UIWindow _setHidden:forced:] + 276 12 UIKit 0x000000010b32c65c -[UIWindow makeKeyAndVisible] + 42 13 UIKit 0x000000010b2d7191 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628 14 UIKit 0x000000010b2d9e5c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350 15 UIKit 0x000000010b2d8d22 -[UIApplication workspaceDidEndTransaction:] + 179 16 FrontBoardServices 0x00000001101802a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 17 CoreFoundation 0x000000010a986abc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 18 CoreFoundation 0x000000010a97c805 __CFRunLoopDoBlocks + 341 19 CoreFoundation 0x000000010a97bfc3 __CFRunLoopRun + 851 20 CoreFoundation 0x000000010a97ba06 CFRunLoopRunSpecific + 470 21 UIKit 0x000000010b2d8799 -[UIApplication _run] + 413 22 UIKit 0x000000010b2db550 UIApplicationMain + 1282 23 Juxta 0x000000010960d69e top_level_code + 78 24 Juxta 0x000000010960d6da main + 42 25 libdyld.dylib 0x000000010d5e1145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

What do I do about this? Here's my code in ViewController:

import UIKit

class ViewController: UIViewController {



    @IBAction func addVote() {
    }

    class ViewController: UIViewController {

     override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        var testObject = PFObject(className:"TestObject")
        testObject["foo"] = "bar"
        testObject.saveInBackgroundWithTarget(nil, selector: nil)

        var voteCount = PFObject(className:"CountOption1")
        voteCount["votes"] = 0
        voteCount["optionName"] = "Crepes"
        voteCount.incrementKey("votes")
        voteCount.saveEventually()

        var query = PFQuery(className:"CountOption1")
        query.getObjectInBackgroundWithId("o74RWVsbHs") {
            (voteCount: PFObject!, error: NSError!) -> Void in
            if error != nil {
                NSLog("%@", error)
            } else {
                voteCount["votes"] = 0
                voteCount.incrementKey("votes")
                voteCount.saveInBackgroundWithTarget(nil, selector: nil)
            }
        }
    }

    }
    class Counter {
        var voteCount: Int = 1
        func incrementBy(amount: Int) { voteCount += amount
            println(" \(voteCount) votes")
            }

    }

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

}

1 Answer

It sounds like you deleted an @IBOutlet or something like that from your code, but not your .storyboard file. Pasan actually covers how to track down and fix this bug in this video