Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert int to NSString?

Tags:

objective-c

I'd like to convert an int to a NSString in Objective C.

How can I do this?

like image 505
Yogini Avatar asked Sep 03 '09 10:09

Yogini


People also ask

How do you convert something to a string in Swift?

To convert an Int value to a String value in Swift, use String(). String() accepts integer as argument and returns a String value created using the given integer value.


2 Answers

Primitives can be converted to objects with @() expression. So the shortest way is to transform int to NSNumber and pick up string representation with stringValue method:

NSString *strValue = [@(myInt) stringValue]; 

or

NSString *strValue = @(myInt).stringValue; 
like image 171
VisioN Avatar answered Oct 14 '22 09:10

VisioN


NSString *string = [NSString stringWithFormat:@"%d", theinteger]; 
like image 22
Silfverstrom Avatar answered Oct 14 '22 09:10

Silfverstrom