How to place __NSCFNumber in an NSString?

I have a variable NSNumbercalled task_id. I want to place this variable NSNumberin NSString(post request). Here is what I tried:

NSString *post = [NSString stringWithFormat:@"&task_id=%@", task_id];

and

NSString *post = [NSString stringWithFormat:@"&task_id=%@", [NSString stringWithFormat:@"%@",task_id]];

For some reason, the line does not include the task_id value in the POST request. How can I put NSNumberin a string?

Update

task_id is NSCFNumber according to this code:

NSLog(@"%@", [task_id class]);

Many thanks,

Peter

+3
source share
3 answers

Thanks for all the efforts. It turns out that this is not a problem, and the problems lie in the web server!

I misunderstood all this,

Thanks guys,

Peter

+1
source
NSNumber *myNumber = @12;
NSString *myString = [myNumber stringValue];
NSString *post = [NSString stringWithFormat:@"&task_id=%@", myString];

This has already been answered here.

+7
source

. , task-id is just an int,

NSString *post = [NSString stringWithFormat:@"&task_id=%d", task_id.intValue];
+2

All Articles