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).





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.