Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert NSinteger to String [duplicate]

I want to convet int to string in objective c how to do that.

my code.

for (i=0; i<=200; i=i+10) {
    // here i want to convet the value of i into string how to do this 

}   

Thanks in Advance.

like image 905
Nauman.Khattak Avatar asked Sep 29 '10 12:09

Nauman.Khattak


2 Answers

Try this:

NSMutableString *myWord = [[NSMutableString alloc] init];
for (int i=0; i<=200; i=i+10) {
    [myWord appendString:[NSString stringWithFormat:@"%d", i]];
    //...
}
//do something with myWord...
[myWord release];

NSInteger is simply a typedef to the int or long data types on 32/64-bit systems.

like image 133
Jacob Relkin Avatar answered Sep 30 '22 22:09

Jacob Relkin


NSInteger n = 13;
NSString string = @(n).stringValue;

Reference see Objective-C literals - literals remove lots of ugly boilerplate code cluttering up your codebase: http://clang.llvm.org/docs/ObjectiveCLiterals.html

like image 24
n13 Avatar answered Sep 30 '22 23:09

n13