I have an NSTextField
into which I need the user to enter a number between a max and min, and it would be nice if I could detect when the NSNumberFormatter
fails that particular test so I can either display a nicer message ("The number is too large" is not very helpful, it needs to display the valid range) or simply set the field automatically to the nearest valid value.
I've looked at the NSTextField
delegate's ‑control:didFailToFormatString:errorDescription:
method which doesn't seem to allow you to modify the error, and I've looked at overriding the NSNumberFormatter
's ‑getObjectValue:forString:range:error:
method which does give me an NSError
that I can modify, but there doesn't seem to be any way to determine which specific error was returned.
Since I am just entering a simple integer, I don't need most of the functionality in NSNumberFormatter
, would I be better off just writing my own formatter from scratch?