user393273
user393273

Reputation: 1438

NSData not working correctly

NSData *myRequest = [NSString stringWithFormat:(@"&site=%@&key=%@",tmpSite,tmpKey)];

Why is this not working ?

Thanks

Upvotes: 0

Views: 148

Answers (2)

Thomas Clayson
Thomas Clayson

Reputation: 29925

NSData *myRequest = [[NSString stringWithFormat:(@"&site=%@&key=%@",tmpSite,tmpKey)] dataUsingEncoding: NSASCIIStringEncoding];

You can't just mix the two classes like that.

Upvotes: 1

Hemant
Hemant

Reputation: 19826

Problem is that you are assigning NSString instance to variable of NSData type. Try this:

NSString* s = [NSString stringWithFormat:@"&site=%@&key=%@",tmpSite,tmpKey];
NSData* d = [s dataUsingEncoding:NSASCIIStringEncoding]; //or any other encoding!

Upvotes: 7

Related Questions