views:

110

answers:

2

Getting "NSMutableDictionary may not respond to '-setValue:forKey:'" error from this code:

NSMutableDictionary *parameters = [[[NSMutableDictionary alloc] init] autorelease];
MKFacebookRequest *request = [MKFacebookRequest requestWithDelegate:self];

//set up parameters for request
[parameters setValue:[NSArray arrayWithObjects:[fbConnection uid], @"123456789", nil] forKey:@"uids"];
[parameters setValue:[NSArray arrayWithObjects:@"first_name",@"last_name",nil] forkey:@"fields"];

//send the request
[request sendRequest:@"users.getInfo" withParameters:parameters];

Any ideas?

Console Error:

2010-08-12 15:23:45.419 App[322:a0f] -[NSCFDictionary setObject:forkey:]: unrecognized selector sent to instance 0x46fa00
2010-08-12 15:23:45.419 App[322:a0f] -[NSCFDictionary setObject:forkey:]: unrecognized selector sent to instance 0x46fa00
+2  A: 

forKey: not forkey:

also, the proper method to use for NSMutableDictionary is setObject:forKey:

vakio
still getting the same error, except "...may not respond to '-setObject:forkey:'". I'm doing desktop dev, not iPhone if that helps. any ideas?
James Eggers
getting this error from the console btw: 2010-08-12 15:23:45.419 App[322:a0f] -[NSCFDictionary setObject:forkey:]: unrecognized selector sent to instance 0x46fa002010-08-12 15:23:45.419 App[322:a0f] -[NSCFDictionary setObject:forkey:]: unrecognized selector sent to instance 0x46fa00
James Eggers
Oh. Yeah I think on desktop it is setValue, however your second forKey is forkey: maybe that's it.
vakio
check your capitalization. the K in Key is capitalized in the method, and not in your code.
Jesse Naugher
thanks!! forKey wasn't capitalised :-/
James Eggers
@James, if this works for you, please click the checkbox so vakio can get credit for giving you the answer
Matt Williamson
It's not exact that the correct method to call is `-setObject:forKey`; you can also use `-setValue:forKey`.
kiamlaluno
+1  A: 

Are you sure the error message is not reporting that "NSMutableDictionary may not respond to '-setValue:forkey:'"?
Objective-C is case sensitive.

NsMutableDictionary has both the metods -setValue:forKey:, and -setObject:forKey:; the difference is that, if the value passed as first parameter to -setValue:forKey: is nil, then the method will remove the key using -removeObjectForKey:.

kiamlaluno