> On 07 Nov 2015, at 10:09, Luc Van Bogaert <luc.van.boga...@me.com> wrote:
> 
>> On 07 Nov 2015, at 01:56, Quincey Morris 
>> <quinceymor...@rivergatesoftware.com 
>> <mailto:quinceymor...@rivergatesoftware.com>> wrote:
>> 
>> On Nov 6, 2015, at 15:23 , Luc Van Bogaert <luc.van.boga...@me.com 
>> <mailto:luc.van.boga...@me.com>> wrote:
>>> 
>>> In a tableview with a content binding and a value binding on the table cell 
>>> view textfields to the model's objectValue keypaths, I'm having trouble 
>>> getting the key-value validation to work correctly. In the model class, I 
>>> have implemented the required validation methods (validateKey(_ :) throws), 
>>> for each of the properties, but the validation method only seems to get 
>>> called for scallar types and not for eg. String types. I've made sure I 
>>> checked "Validates immediately" in the binding attributes.
>> 
>> a. When you edit the text fields, does the model String property get updated?
>> 
>> b. Can you show us an example function signature line for a scalar 
>> validation method, and one for a string validation method?
>> 
>> c. Can you show us an example of a model key path you’re using when binding 
>> to objectValue?
>> 
>> It occurs to me that there might be a bridging issue here. Note that the 
>> generic validation method (which is what routes the validation to a specific 
>> validate<Key> method) looks like this in the Swift version of 
>> NSKeyValueCoding.h:
>> 
>>          public func validateValue(ioValue: 
>> AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey inKey: String) throws
>> 
>> It’s possible that the validate<Key> method declaration needs to be 
>> something like this. (According to this theory, the scalar validation works 
>> because the object<->scalar conversion happens within KVC, and so it’s 
>> staying within the Obj-C type world.)
>> 
>> Does the model object inherit from NSObject and/or conform to NSObject 
>> protocol?
>> 
> 
> a. Yes, I can edit the textfields in the tabel and the change is persistent 
> so the model gets updated.
> 
> b. For title: String property :
> 
>     func validateTitle(ioValue:
>         AutoreleasingUnsafeMutablePointer<String?>) throws {...}
> 
> For raise: Float property
> 
>     func validateRaise(ioValue:
>         AutoreleasingUnsafeMutablePointer<NSNumber?>) throws {...}
> 
> 

Reading your explanation again about the bridging issue and KVC working in an 
Objective-C environment, I realised that my method signature was wrong. I 
changed "<String?>" to "<NSString?>"

>     func validateTitle(ioValue:
>         AutoreleasingUnsafeMutablePointer<NSString?>) throws {...}

This is working correctly now, the method is called when I change the table 
texfield.
Thanks

-- 
Luc Van Bogaert

_______________________________________________

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