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];

Add your voice!

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