On Feb 26, 2017, at 12:40 , Luc Van Bogaert <luc.van.boga...@me.com> wrote:
> 
> my model class overrides 
> 
> validateValue(_ ioValue: AutoreleasingUnsafeMutablePointer<AnyObject?>, 
> forKey inKey: String) throws
> 
> After changing the text in the textfield, my validation method is not called. 
> When I replace my custom formatter with an instance of NSNumberFormatter, 
> everything works as expected.

You don’t say whether your custom formatter is used for formatting, and it’s 
just validation that’s missing, or if the formatter is totally ignored. It 
might be worth adding code that checks to see if the field has a formatter, and 
if the formatter has the correct class. Or, if the NIB loading calls a 
different initializer than you were expecting, then perhaps your formatter 
isn’t being set up properly.

I have a vague recollection that there was an IB bug where custom formatters 
were not honored, which was fixed in a recent version of Xcode. However, I 
can’t find anything about this in the release notes, so I may have dreamed it. 
Still, it might be worth trying this in the latest Xcode beta.

Also, I would not recommend overriding validateValue(_:forKey:) directly, since 
that overrides the entire KVC  validation mechanism. That shouldn’t be a 
problem if you invoke the super implementation properly for keys you don’t 
handle, but it’s probably safer and clearer to use a custom validation method 
of the form validate<key>(_:). See:

        
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/ValidatingProperties.html
 
<https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/ValidatingProperties.html>


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to