Is it possible to add NSManagedObject to a selected parent object with just Interface Builder and Core Data?

I'm learning Core Data and for now just using Interface Builder and XCode Data Model (following examples from Aaron Hillegass Cocoa book).

I have an MVC app and master data set up and running in an interface builder (not written by hand yet). I created various array controllers, views and buttons to add and remove objects and edit data and define relationships between objects.

However, my object model is strictly hierarchical parent-child (and grandchildren), and each relationship is one-to-many. So when I add a child (or grandchild), I want to automatically assign the parent currently selected in the main tableView as the parent of the new child.

Is this possible in the interface constructor or is this the point at which I should start coding my own methods?

Any pointers on the next step that I should be looking for, or how to figure it out, I really appreciate. I am just stuck and cannot find a related tutorial or link.

Perhaps it will help if I describe my document window. It has two tables with add / remove buttons. The tableView on the right displays the NSSet of the children of the parent selected in the tableView on the left. I want to add a button on the right to add a new object and automatically make it a child of the selected parent so that it appears in the tableView on the right.

At the moment, the only methods I can see on arrayController for child objects are add: and remove: but of course they do not bind the new object to the selected parent. Should I add my own method (IBAction) to the parent, i.e. addChildObject :? Or is there a built-in way to automatically add a child to CoreData based on parent-child relationships?

+2


source to share


1 answer


The problem has been resolved. I found a tutorial (albeit a bit outdated) that describes exactly what I'm trying to do:

https://developer.apple.com/cocoa/coredatatutorial/index.html



And after careful sequential sequential step, I realized that I did everything right, I just missed one binding: I only set the Content Set of the child array controller, not its Managed Object Context (file owner). This is the only reason my add button wasn't adding a new child! A trivial mistake, but when you are not sure if you are in doubt, you are whole and not looking for a simple mistake. Sorry for everyone who should have read this, but maybe the tutorial link will help someone.

0


source







All Articles