Phil
Phil

Reputation: 3045

"this class is not key value coding-compliant for the key"

I feel like I'm missing something obvious here but I'm new to obj-c so maybe it's just something I'm not aware of.

I'm getting the exception error at runtime...

NSDictionaryI 0x9d384d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key overObject.'

On the 4th line of this code...

NSDictionary *tempDictionary = [[NSDictionary alloc] init];

    Boolean overObjectYES = NO;
    Boolean overObjectNo = NO;

    [tempDictionary setValue:[NSNumber numberWithBool:overObjectYES] forKey:@"overObject"];

Upvotes: 3

Views: 7977

Answers (3)

Kendall Lister
Kendall Lister

Reputation: 335

I think this is a combination of using NSDictionary when you mean NSMutableDictionary, and sending the message setValue when setObject is generally considered more appropriate. See this question for details:

NSDictionary setValue:forKey: -- getting "this class is not key value coding-compliant for the key"

Upvotes: 9

Tim
Tim

Reputation: 60150

Do you mean tempDictionary to be a mutable dictionary? If so, declare it as:

NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] init];

Upvotes: 4

user427969
user427969

Reputation: 3896

Use NSMutableDictionary. NSDictionary is not editable.

NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] init];
Boolean overObjectYES = NO;
Boolean overObjectNo = NO;

[tempDictionary setValue:[NSNumber numberWithBool:overObjectYES] forKey:@"overObject"];

Upvotes: 1

Related Questions