NSString is integer?
Something like this:
NSScanner* scan = [NSScanner scannerWithString:toCheck];
int val;
return [scan scanInt:&val] && [scan isAtEnd];
You could use the -intValue
or -integerValue
methods. Returns zero if the string doesn't start with an integer, which is a bit of a shame as zero is a valid value for an integer.
A better option might be to use [NSScanner scanInt:]
which returns a BOOL
indicating whether or not it found a suitable value.