Search code examples
objective-cxcodecore-datacocoa-bindings

What Happened to Core Data Bindings?


I've been out of the loop for a while, but it used to be you could use Interface Builder to add an NSArrayController, set it's mode to Entity, and bind the managedObjectContext to the MOC of the AppDelegate. That doesn't seem to work anymore.

I've read through the documentation, (of course it's very possible I missed something) but I haven't yet found a way to bind my Array Controller to my Core Data stack. Somewhere along the line things got "simplified". What is the preferred way to get objects from Core Data to my NSTableView?


For more details, I currently have a fairly empty non-document project, no storyboards, with no modifications to the App Delegate, but I did add a property on my App Controller to access the MOC:


@interface JBAppController : NSObject

@property (nonatomic, readonly) NSManagedObjectContext* managedObjectContext;

@end

@implementation JBAppController

...
- (NSManagedObjectContext*)managedObjectContext
{
    return [[(AppDelegate *)[[NSApplication sharedApplication] delegate] persistentContainer] viewContext];
}

...

I'll probably redo this once I understand what the bindings are missing, or if we aren't meant to use bindings anymore, however the right way to get the data to the tableview is.


Solution

  • Control-drag:

    Control-drag to the property, configure the binding and click on Connect.

    enter image description here

    Bindings Inspector:

    Configure the binding and turn on the Bind to checkbox.

    enter image description here