How to convert an NSString into an integer

- by

Imagine you had an NSString and wanted to save it as an integer value.
You can use the intValue method for that:

NSString *myString = @"47";
int myInt = [myString intValue];

To do the reverse, you can use the initWithFormat method:

int myInt = 32;
NSString *myOtherString = [[NSString alloc]initWithFormat:@"%i", myInt];


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

Add your voice!

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