I've created a subclass of UITextField which has its own visual style and functionality. The functionality is to restrict the user to decimal currency values (for example, 3.50), but that's not really relevant because I know the algorithm I have works. The issue is that I want to contain that logic in the text field subclass itself. So far I've succeeded in capturing the delegate equivalents of textFieldDidBeginEditing and textFieldDidEndEditing:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBeginEditing", name: UITextFieldTextDidBeginEditingNotification, object: self)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEndEditing", name: UITextFieldTextDidEndEditingNotification, object: self)
Working well. Now I need a way to check if the user is entering valid input and update its text only if that character is valid (like shouldChangeCharactersInRange, but without a delegate), but I need to do this from within that text field subclass itself. Otherwise, I'm just repasting 40 lines of code in every view controller that has this type of field.