I have an NSScanner in a custom NSNumberFormatter that scans for non-int values but I want it to skip "-" (dash)
- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error {
if ([partialString length] == 0) {
return YES;
}
NSScanner *scanner = [NSScanner scannerWithString:partialString];
if (!([scanner scanInt:0] && [scanner isAtEnd])) {
return NO;
}
return YES;
}
I thought I had to use [scanner charactersToBeSkipped]
but I don't know how that works
I came up with my own solution. Each time a character is typed, it checks if the first one is a dash. If it is, it skips the first character and checks if the rest of the string contains ints. If the first character is not a dash, it scans the whole string for ints.