Question

I have an app that uses core data. The model of which has 3 Entities, all connected by 1-many relationships as so:

|E1|<-->>|E2|<-->>|E3|

My UI is essentially a 3-way vertical split pane, each with a tableview in. The way it works is that I have each window incrementally 1 layer down, essentially allowing the user to 'drill' down from E1 objects to E3 objects, all linked by relationships, similar to the option in OSX finder.

Each table is populated by an NSArrayController, getting it's data from the relevant Entity, and also on what is selected in the previous 'drill-down' window. This all works fine if I simply hook up a button to the addObject method of the array controller, however the new object it makes is a blank row, one that I have to fill in manually.

I have hooked up the add button to open an 'Open Dialogue', which allows the user to select files. I then iterate through the array of NSURL's returned, and add the file information to the E3 entity of the core data model. I call save, but nothing appears in the UI. I'm guessing that this is something to with the fact that the object i'm adding has no way of knowing which E2 it belongs to, and therefore isn't showing.

Is there a way to add an object to the core data model with relationships? For example, I could see what object was selected in E2, and then add the object with a relationship to this. I hope I've made this clear enough. Any ideas or suggestions are more then welcome!

Was it helpful?

Solution

I sorted this by creating an object, setting it's properties, then calling addObject:id on the array controller.

Hope this helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top