I have an NSTextField in which I need the user to enter a number between the maximum and minimum, and it would be nice if I could detect when the NSNumberFormatter fails in this particular test so that I can either show a more pleasant message ("Too a large number "is not very useful, it needs to display a valid range) or just set the field automatically to the nearest valid value.
I looked at the NSTextField delegate ‑control:didFailToFormatString:errorDescription: , which doesn't seem to allow you to change the error, and I looked at overriding the NSNumberFormatter ‑getObjectValue:forString:range:error: method, which gives me an NSError that I can change, but There seems to be no way to determine which specific error was returned.
Since I just go into a prime integer, I don't need much of the functionality in NSNumberFormatter , is it better for me to write my own formatter from scratch?
validation objective-c cocoa macos nsnumberformatter
Simon broadhead
source share