> On 07 Nov 2015, at 01:56, Quincey Morris
> <[email protected]> wrote:
>
> On Nov 6, 2015, at 15:23 , Luc Van Bogaert <[email protected]
> <mailto:[email protected]>> 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 {...}
c. I'm binding to "objectValue.title"
declaration of the String property:
class Album: NSObject {
var title: String
declaration of the Float property:
class Employee: NSObject {
var raise: Float = 0.05
Note that the model indeed inherits from NSObject.
--
Luc Van Bogaert
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]