Possible Duplicate:
NSString is integer?
I've been searching around for the last half hour trying to find an easy way to convert an instance of NSString into an integer, and to be able to tell if the string was validly formatted. So far, I haven't been able to find anything. There's the intValue
and integerValue
methods in NSString, but these just return 0 if invalidly formatted. In my case, 0 is a valid number. There's also NSNumberFormatter, which will parse a decimal number without a problem, but as far as I can tell it doesn't do integers, although I might just be missing something.
It seems like this is too simple of a problem to be omitted from Foundation. I'd appreciate somebody pointing me in the right direction.