Your question is a bit confusing for me. Here is how I understand what you want to do:
You have an NSArray named phoneNumDigits . This array contains several NSString objects. Each line is something like @"1" or @"4" and is a single digit phone number.
Now you want to convert each of these strings of digits to int or NSInteger and want to store these integers in another array.
If I understand you correctly, here is my answer:
You cannot exactly do what you want, because you cannot put a simple data type, such as int or float in an NSArray .
This is why there is an NSNumber wrapper NSNumber . You can pack a simple int in NSNumber and store that NSNumber in NSArray .
So, to get the string digits from phoneNumDigits to the tmp array, you can use this code:
for (NSString *digitAsString in phoneNumDigits) { NSNumber *digitAsNumber = [NSNumber numberWithInt:[digitAsString intValue]]; [tmp addObject:digitAsNumber]; }
To get int from tmp- NSArray you have to use
int digit = [[tmp objectAtIndex:idx] intValue];
Hope this helps, but I'm not sure I understand what you want to do here. I could completely skip this. Perhaps you could share some more codes.
source share