Search code examples
cocoacore-dataxcode4

How do I connect to the ManagedObjectContext object of the File Owner in XCode 4


I'm building a really simple Core Data app in XCode 4. There's an entity model with just one entity (Employee) and just one attribute (name).

In IB I've added a default Table View to display the employees, two buttons (one to add an employee and another to delete an employee) and an ArrayController.

It is my understanding that the ArrayController's managedObjectContext somehow needs to be connected to the one that is initialised by the App Delegate. I can see the code for initialising the context but IB does not let me connect to it.

How do I do this connection?

Many thanks.


Solution

  • How does Interface Builder not allow you connect it? Bindings are not the same as IBOutlets in Interface Builder context. If file owner is instance of AppDelegate (which always has initial managed object context) you just should define NSArrayController's managedObjectContext binding's object as File's owner and set managedObjectContext as its model path.