iphone - Problem casting an int as a NSString -


i working on iphone app using urls , running difficulty appending ints onto end of them. have following line of code

        nsurl *urlcards = [[nsurl alloc] initwithstring:(@"http://website.edu/get_stuff/%@",[nsstring stringwithformat:@"%d",_stuffid])]; 

that need appending int end of. when print out results of nsurl urlcards, value of int passing in, or value of _deckid.

i have verified _deckid declared merely local int indeed have correct value @ run time.

what missing?

thanks!!

what you've encountered comma operator. comma operator evaluates each of operands side effects, , evaluates result of last expression. example:

int i; int j; int z;  z = (i = 4, j = 3, + j); // z 7 

what you've got here:

(@"http://website.edu/get_stuff/%@",[nsstring stringwithformat:@"%d",_stuffid]) 

evaluates just

[nsstring stringwithformat:@"%d", _stuffid] 

this because first part @"..." expression has no side effects, , result of comma operator result of [nsstring stringwithformat:] method.

what looking think, this:

nsstring *urlstring = [nsstring stringwithformat:@"http://website.edu/get_stuff/%d",_stuffid]; nsurl *urlcards = [[nsurl alloc] initwithstring:urlstring]; 

you can in 1 line, kingofbliss's answer.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -