3

In Xcode 6.2, in the Bindings Inspector I see this:

enter image description here

Can anyone explain what setting the Controller Key to selection means? The Apple docs say:

selection:
Returns a proxy object representing the [NSObjectController's] selection.

Not at all helpful.

7stud
  • 46,922
  • 14
  • 101
  • 127
  • It's one-way and useful in the subclasses, where you could do something like bind an NSObjectController's `content` to the `selection` of an NSArrayController that allows only single selection... I don't think there's much more to say since there's apparently no way to set the selection with a simple NSObjectController instance. It's intentionally useless in the superclass as far as I know. – stevesliva May 26 '15 at 18:04

1 Answers1

0

I've pieced together part of the puzzle. From Apple Developer docs:

Controllers require content to manipulate and there are a number of options for setting this content. It can be done ... through bindings...
...
NSObjectController and its subclasses are initialized with the method initWithContent:, passing a content object or nil if you intend to use the content bindings. You can explicitly set the content of an existing controller using the setContent: method. It is far more common to provide content for controllers by establishing a binding to one of their exposed Controller Content bindings.

NSObjectController exposes a single binding for content called contentObject. You can establish a binding from contentObject to any object that is key-value-coding and key-value-observing compliant for the keys that you intend to have the controller operate on.

From an SO post:

For an NSObjectController, the selection is the content object.

Apparently, the selection @property of the NSObjectController is assigned the contentObject, which is the thing that enables you to do bindings.

More generally:

NSObjectController and its subclasses ... support tracking of the currently selected object or objects

I think currently selected object must mean the control that is selected in the View.

There are two methods that are commonly used to access the objects that are currently selected: selection and selectedObjects.

I think that with an NSObjectController, the selected control in the View is meaningless, and therefore the selection @property of the NSObjectController is assigned the contentObject.

Community
  • 1
  • 1
7stud
  • 46,922
  • 14
  • 101
  • 127
  • I'm having trouble parsing "the selection @property of the NSObjectController is assigned the contentObject, which is the thing that enables you to do bindings." Both `selection` and `content` allow bindings, but selection is one-way. Like I said in the comment, `selection` makes more sense as implemented by `NSArrayController` and `NSTreeController`. Same goes for `addObject`, `removeObject`, and `newObject`. – stevesliva May 28 '15 at 17:21