Reputation: 47
I'm working my way through Cocoa Programming for Mac OS X (4th Edition), and, like many others, I'm getting stuck on a challenge; specifically, Chapter 8, Challenge 1. Unable to come to the solution on my own, I tracked down a little help from the Life as Clay blog. I added the solution there but I'm getting the following error:
2013-05-09 00:28:49.049 RaiseMan[58078:303] Error setting value for key path sortDescriptors of object <NSArrayController: 0x7fcee2a51900>[object class: RMPerson, number of selected objects: 1] (from bound object <NSTableView: 0x7fcee2a48750>): [<RMPerson 0x7fcee1c5c870> valueForUndefinedKey:]: this class is not key value coding-compliant for the key [personName valueForKeyPath:@"length"].
The thing is, in trying to hunt down what's wrong, I've seen this error crop up all over the place on StackOverflow and I've yet to discern what information it's trying to convey about my project. I can't find any correlation between solutions to understand this error message, so I can't use it to figure out what's going on in my code.
So, long story short, I'm not really looking for help with what is specifically wrong with my code, and more trying to find out what this error message actually means, so I can hunt down the problem myself; however, here's what I'm trying to do anyway. If you can tell me not just what's wrong, but also why this error applies to what I'm doing, that would be great.
In this particular instance, I have a TableView bound to an ArrayController. The ArrayController is bound to File's Owner, with employees
(an NSMutableArray) as its Model Key Path. employees
is an array of RMPerson
objects, each of which has two properties: personName
(an NSString) and expectedRaise
(a float). The first column of the table shows personName
from the respective RMPerson
; I am attempting to sort the first column using the length of personName
as per the challenge. When I sort it using personName
as the sort key and caseInsensitiveCompare:
as the selector, all is well. This error crops up when I use either [personName valueForKeyPath:@"length"]
or personName.length
as the sort key and compare:
as the selector.
Upvotes: 2
Views: 2803
Reputation: 153
So , if you found this "Class is not coding value complient" strange error with some IBOutlet variable name not present in your Project, Try Delete app and Reinstall it Again on Simulator. Worked for Me!
Upvotes: 0
Reputation: 96323
What does “this class is not key value coding-compliant” mean?
Nothing.
The full exception message makes the question more meaningful:
What does “this class is not key value coding-compliant for
<key>
” mean?
It means that objects of that class do not have a property named <key>
, at least as far as Key-Value Coding is concerned, so you can't use KVC to get a value for such a property from them.
Bindings, of which NSArrayController is a vital part, uses KVC to get and set both bound properties and the properties you've bound them to, so trying to bind something to a property that doesn't exist will get you this exception.
You've got a special case of this, though:
…RMPerson …: this class is not key value coding-compliant for the key [personName valueForKeyPath:@"length"].
What this means is that you tried to use “[personName valueForKeyPath:@"length"]
” as a key.
Strictly speaking, KVC will accept as a key pretty much anything that doesn't have a period in it, but in practice, very few objects recognize any key that isn't an identifier, and all of them (except NSDictionary) expect keys to at least be single words. An Objective-C message expression is not a valid key and cannot be part of a key path.
I'm guessing that you actually pasted “[personName valueForKeyPath:@"length"]
” into a Model Key Path field in your nib—for an array controller's sortDescriptors
binding, from the looks of it. That won't work. The Model Key Path field expects the key path itself, alone.
personName.length
would be a valid key path, but assuming that your RMPersons' names are strings, that isn't going to get you an array of sort descriptors, so you can expect the array controller to choke on the array of numbers.
Whatever you're trying to do (sort by length of name?), you should ask another question about that.
When I sort it using
personName
as the sort key andcaseInsensitiveCompare:
as the selector, all is well. This error crops up when I use either[personName valueForKeyPath:@"length"]
orpersonName.length
as the sort key andcompare:
as the selector.
The selector isn't important.
Pay attention to whether something expects a key path or just a key—the distinction is subtle, but app-breakingly important. A sort descriptor requires a single key.
Upvotes: 1
Reputation: 1028
It means you are trying to access/set the value of the object by it's key but that it doesn't have any key-value pair.
In your case, you are trying to set the value of an NSMutableArray by it's key, which is not possible.
Upvotes: 0