tags:

views:

2214

answers:

3

can anyone tell how to convert from int to string

+8  A: 
NSString *string = [NSString stringWithFormat:@"%d", theinteger];
Silfverstrom
+5  A: 

2 minutes of looking through the XCode documentation would tell you this...

int i = 25;
NSString *myString = [NSString stringWithFormat:@"%d",i];

is one of many ways...

h4xxr
A: 

h4xxr, I would say that searching the docs for "int to string" or similar and getting a hundred unrelated topics back is not intuitive, or good. Someone with a few weeks of experience would have the hunch that he should create an NSString object and finds a good page with lots of methods. Searching that page for the word "integer" gives f.ex. integerValue, which is the other direction of conversion. From that method there are no See Also links to the other direction, which is not very logical.

stringWithFormat as the solution is not immediately apparent, except to those getting a paid for education in the language. This method has its own page with formatting examples and therefore isn't found by searching for "integer" on the NSString page.

So, you tell me. Findable in two minutes for someone who hasn't used it in a previous app? Ahem.

Henrik Erlandsson
Welcom to Stackoverflow. You will soon discover that the best use of [Post Your Answer] button is to actually answer the question asked at the top of the page. When you get enough reputation you will be able to add comments to existing answers.
mouviciel
Thanks :) Might as well register and read the FAQ, since this seems the ticket compared to other sites. I'm not confident I can answer any but the most rudimentary questions yet, as I've just started. But having used the XCode docs for some weeks and finding my answer here in _under_ two minutes, I got the urge to respond.
Henrik Erlandsson