Q:

Cocoa textbox to update variable

I've got a textfield with number formatter which is bound to a variable with Cocoa bindings. 
There's also a stepper which I've bound to the same variable to increment the value, I've used an NSLog to test and it works great. 
My problem is: Whenever I type a number into the box the variable isn't updated unless i hit enter. How does NSTextBox know when the user is finished entering? Is there a way to dynamically update the variable after every digit entered?
Many thanks
Rich 

A:

First, are you sure you want it to update immediately? One of the user's keystrokes could be an invalid character (ie, not a number). An NSNumberFormatter can help but I believe you still have to "commit" the entry before it will validate it as a proper number entry.
Second, you could always implement the -textDidChange: NSTextDelegate method. Again, same problem as above, though. Invalid input could trigger. To work around this, you could try creating an NSNumber from the string input and if you don't get an NSNumber, don't bother reacting until you do (and if the field loses focus with invalid input, change it back to its last valid value) but then you're duplicating the "validate on commit" NSNumberFormatter behavior you get for free.

