5

I have a pretty simple set up here, and Xcode is giving me a comment-less red "!" mark in the interface builder.

Started from a Core Data-based document template. The document xib has an NSObjectController instance, whose Managed Object Context is bound to the File's Owner (my NSPersistentDocument subclass). An NSTextField is present, whose Value I want to bind to the NSObjectController...and this is where the problem comes in.

I type "title" for the "Model Key Path," because that's the correct property for my NSManagedObject, which should appear in the text field. When I click into the empty Controller Key field, the autocompletion bizarrely suggests fields that are only for NSArrayController:

screenshot of strange autocomplete candidates

Any time I try to type "content" as the Controller Key (because that's the correct property for an NSObjectController) and then hit Tab/Return/whatever, the "content" is shifted down to the Model Key Path, like so:

screenshot of error

What is this red exclamation mark for? When I leave "Controller Key" empty and "Model Key Path" as content.title, the app works. The binding is correct and reflects the "title" property of my NSManagedObject. I am absolutely sure that "Object Controller" is an instance of NSObjectController.

Khakionion
  • 742
  • 7
  • 20
  • To make sure there's enough info here: The NSObjectController is in Entity mode, set to my Core Data entity that has an String property named "title." – Khakionion May 21 '12 at 19:25

1 Answers1

8

Use "selection". For an NSObjectController, the selection is the content object.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • So...that works, but why? That's not documented anywhere that I can find, and is completely counter-intuitive. There is no "selection" because it's just a single object, right? – Khakionion May 21 '12 at 21:55
  • https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Concepts/CntrlSelection.html#//apple_ref/doc/uid/TP40002146-BCICADHC – Khakionion May 21 '12 at 22:00
  • The above documentation mentions that behavior in a single sentence. Still seems counter-intuitive, but at least it is mentioned in a single place throughout all of Apple's documentation. – Khakionion May 21 '12 at 22:00