tangobango
tangobango

Reputation: 381

Convert NSUInteger to string with ARC

I'm trying to cast a NSUInteger to a string so I can print a message. From searching, it seems like I need to use stringWithFormat, but I am getting an error that an implicit cast not allowed with ARC.

Here's the line in question:

NSString *text = [[NSString stringWithFormat: (@"%li",  NSUInteger)];

I've tried changing the format specifier to %lu with no help.

Thanks.

Upvotes: 3

Views: 10636

Answers (1)

TotoroTotoro
TotoroTotoro

Reputation: 17622

You probably have a variable of type NSUInteger, something like

NSUInteger myNumber;

Then you can convert it to a string like this:

NSString *text = [NSString stringWithFormat:@"%li",  myNumber];

A solution that I prefer now is this:

NSString *text = [NSString stringWithFormat:@"%@",  @(myNumber)];   

This helps avoid compile warnings about incorrect number formatting codes (after a long time I still get confused in them).

Upvotes: 24

Related Questions