How does one convert NSInteger
to the NSString
datatype?
I tried the following, where month is an NSInteger
:
NSString *inStr = [NSString stringWithFormat:@"%d", [month intValue]];
NSIntegers are not objects, you cast them to long
, in order to match the current 64-bit architectures' definition:
NSString *inStr = [NSString stringWithFormat: @"%ld", (long)month];
Obj-C way =):
NSString *inStr = [@(month) stringValue];
An NSInteger
has the method stringValue
that can be used even with a literal
NSString *integerAsString1 = [@12 stringValue];
NSInteger number = 13;
NSString *integerAsString2 = [@(number) stringValue];
Very simple. Isn't it?
var integerAsString = String(integer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With