2

I keep getting this error on my app. The only time I get the error is when I resume the app from a background state. I need some help figuring out where the error lies. It happens every time I go from background to active, no matter what the active ViewController is.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0xc063200> valueForUndefinedKey:]: this class is not key value coding-compliant for the key response.'

user717452
  • 33
  • 14
  • 73
  • 149
  • possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – jtbandes Aug 03 '15 at 06:53

1 Answers1

5

It sounds like somewhere in the stack, a non-existant key is being accessed on an NSString. valueForUndefinedKey is part of Key-Value Coding in Objective-C and is part of NSObject. It can be called when valueForKey: doesn't work out on pretty much any object.

I see that exception thrown the most often when either:

  1. A class with a storyboard of XIB file gets refactored and the storyboard or XIB does not.
  2. You have a major memory issue where you're calling a method on a deallocated object and the wrong piece of memory is getting accessed.
  3. It's a network JSON API in action and the method is getting the wrong type of object serialized from JSON (e.g. an NSString instead of NSDictionary).

Setup an exception breakpoint on All Exceptions in Xcode's Breakpoint Navigator so you can find the exact line in your codeNSUnknownKeyException is being thrown on. Press the (+) to bring up the menu.

Breakpoint Navigator

james_womack
  • 10,028
  • 6
  • 55
  • 74
  • Looks like it was coming on third-party library Xtify for push notifications. This is the line `if ([responseDictionary valueForKeyPath:kParentJson]!=[NSNull null] && [[responseDictionary valueForKeyPath:kParentJson] length] > 0 ) {` – user717452 Mar 27 '13 at 02:34
  • Yes, but `responseDictionary` should likely be an `NSDictionary` and the exception is thrown on an `NSString` factory class (`NSCFString`). So it could be the #2 or 3 scenarios in my list. You can add a test for `responseDictionary` being 'not nil' and an NSDictionary before `if ([responseDictionary valueForKeyPath:kParentJson]...` is called. – james_womack Mar 27 '13 at 02:36
  • I wonder if your app is not able to reach the server or is not authenticating properly and is therefore getting the wrong type of object serialized from JSON. – james_womack Mar 27 '13 at 02:38
  • That may have been issue. Has been resolved now so I think was server related on third-party library end. Thanks for helping me find where it was coming from. – user717452 Mar 27 '13 at 03:02