> On 6 Mar 2017, at 17:34, Jeremy Hughes <moon.rab...@virginmedia.com> wrote:
> 
> It all works now.

Actually, it works as far as the text field displays “Multiple” (placeholder) 
for multiple values, but it doesn’t work when I set a value in the text field. 
In that case I get:

Error setting value for key path selection.self of object <NSArrayController: 
0x6080001c22b0>[object class: NSMutableDictionary, number of selected objects: 
2] (from bound object <NSTextField: 0x6080001e2500>): [<__NSCFNumber 0x337> 
setValue:forUndefinedKey:]: this class is not key value coding-compliant for 
the key self.

The text field is bound to an array of NSNumbers via an array controller (using 
a Swift array that is marked as “dynamic”)

I can get around this by writing a “Number” wrapper:

        class Number: NSObject
        {
                dynamic var value: NSNumber
                
                init(_ value: Int) { self.value = NSNumber(value: value) }
        }
        
        dynamic var values: [Number]

and binding the text field to the “value” field of this wrapper (so the 
controller key is arrayController.selection and the model key path is “value").

But I wonder if it is possible to bind directly to an array of NSNumbers 
without using a wrapper.

I’ve tried doing that using an array of NSNumbers with the model key path set 
to “value” (i.e. the value of the NSNumber) but I get the following error:

 [<__NSCFNumber 0x337> valueForUndefinedKey:]: this class is not key value 
coding-compliant for the key value.

So, unless there’s another key path I can use for NSNumber, I’m guessing it 
isn’t possible to do this.

Jeremy


_______________________________________________

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