Convert from string to integer in Objective C
Next example shows you how to convert a string to integer value.
NSString *aString = @"200"; int anInt = (int)[aString integerValue]; NSLog(@"anInt = %d", anInt);
Note that we use cast to int (int) otherwise we get a warning: “Implicit conversion loses integer precision: ‘NSInteger’ (aka ‘long’) to ‘int’“. Instead of cast to int we could define anInt as long.