Re: Binding NSTextField to an array

2017-03-06 Thread Quincey Morris
On Mar 6, 2017, at 11:31 , Jeremy Hughes wrote: > > But I wonder if it is possible to bind directly to an array of NSNumbers > without using a wrapper. No, but the reason for that and for the trouble you’ve run into is a bit complicated. First of all, you are actually talking about bind *thro

Re: Binding NSTextField to an array

2017-03-06 Thread Jeremy Hughes
> On 6 Mar 2017, at 17:34, Jeremy Hughes 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.sel

Re: Binding NSTextField to an array

2017-03-06 Thread Jeremy Hughes
Bingo and thanks! I had already found the checkbox for “Selects All When Setting Content" The missing piece of the jigsaw was using “selection" as the Controller Key and “self" as the Model Key Path. It all works now. Jeremy -- > On 6 Mar 2017, at 17:12, Mike Abdullah wrote: > > Yep, you’r

Re: Binding NSTextField to an array

2017-03-06 Thread Mike Abdullah
Yep, you’re very close. An array controller is required indeed, it’s the one responsible for vending out NSMultipleValuesMarker. From your earlier message, you’re now seeing an exception or similar: Cannot create number from object <_NSControllerObjectProxy: 0x600070b0> of class _NSControlle

Re: Binding NSTextField to an array

2017-03-06 Thread Jeremy Hughes
> On 6 Mar 2017, at 14:30, Jonathan Mitchell wrote: > > Sounds like NSValueTransformer is in fact what you need. > It can take in your NSArray ref and spit out a single NSString that the > NSTextField binding can live with. I think I must be missing something obvious. The value of an NSTextFie

Re: Binding NSTextField to an array

2017-03-06 Thread Jonathan Mitchell
Sounds like NSValueTransformer is in fact what you need. It can take in your NSArray ref and spit out a single NSString that the NSTextField binding can live with. Defining NSValueTransformer subclass for every binding can be a pain. So I use a block approach. This has the big advantage that you

Re: Binding NSTextField to an array

2017-03-06 Thread Jeremy Hughes
> From what I understand of your example, you’re not “binding” anything in a > Cocoa sense. In the case of the single value, the text field is set up via the Bindings pane of Interface Builder so that “Value" says “Bind to File’s Owner” with a model key path of self.value. (And “value" is decla

Re: Binding NSTextField to an array

2017-03-06 Thread Mike Abdullah
From what I understand of your example, you’re not “binding” anything in a Cocoa sense. What you is an NSArrayController. Bind your text field to the array controller. Supply the array controller with content, and have it derive the selected value, be it single or multiple. > On 6 Mar 2017, at

Binding NSTextField to an array

2017-03-06 Thread Jeremy Hughes
Hi, This seems like an elementary question. I’d like to bind an NSTextField to an array of numerical values, so that the text field will either display a single value if the values are identical or will display a multiple values marker if the values are different. Using Swift, I can bind a tex