How to convert an integer into a string (text object)

I keep forgetting how to do this so here it is: if you have an integer and you want to print it out, say in a UILabel you can use the initWithFormat method of NSString like so:

NSString *myNumber;
myNumber = [[NSString alloc] initWithFormat:@"%d", myInteger];
self.myLabel.text = myNumber;

The secret here is the @”%d” which is called a String Format Specifier (search for it in the Developer Docs).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.