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

- by

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



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

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