In objective c, how can i check if a string/NSNumber is an integer or int
If you're trying to determine whether or not an NSString
has a numeric value or not, try using NSNumberFormatter
.
-(BOOL) stringIsNumeric:(NSString *) str {
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSNumber *number = [formatter numberFromString:str];
[formatter release];
return !!number; // If the string is not numeric, number will be nil
}