Reputation: 12181
I'm trying to send an NSDictionary to a server and have it set up as follows:
NSDictionary *songInfo = [[NSDictionary alloc] initWithObjects:propertyValues forKeys:propertyKeys];
NSURL *exampleURL = [NSURL URLWithString:@"http://www.example.com/activities"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:exampleURL];
[request setValuesForKeysWithDictionary:songInfo];
[request startAsynchronous];
I'm getting the following error:
[<ASIFormDataRequest 0x1035600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 1 Media Type.
Which is puzzling because Media Type is the 14th key in the Dictionary, so how could it have been fine with all the other ones and then flipped out on this?
It seems to not be accepting my Dictionary, but is there any reason why?
Upvotes: 1
Views: 1012
Reputation: 36143
There are several reasons:
ASIFormDataRequest
nor ASIHTTPRequest
override -setValueForKeysWithDictionary:
or -setValue:forKey:
. This means that, unless the keys match up to key-value-coding–compliant keys of the object, you are going to see that exception.Try using a supported method, like -setPostValue:forKey:
:
NSDictionary *songInfo = /*...*/;
ASIFormDataRequest *request = /*...*/;
[songInfo enumerateKeysAndObjectsUsingBlock:
^(id key, id value, BOOL *stop) {
[request setPostValue:value forKey:key];
}];
And in future: USE THE SOURCE.
Upvotes: 2