Re: KVC Validation w/ custom Formatter not working
Re: KVC Validation w/ custom Formatter not working
- Subject: Re: KVC Validation w/ custom Formatter not working
- From: Quincey Morris <email@hidden>
- Date: Mon, 27 Feb 2017 13:58:43 -0800
- Feedback-id: 167118m:167118agYYG0F:167118sXrdRW9QCg:SMTPCORP
On Feb 26, 2017, at 12:40 , Luc Van Bogaert <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden