Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Core Data Woes (current selection and arrays)

Core Data Woes (current selection and arrays)
Thread Tools
11011001
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
May 15, 2005, 05:01 AM
 
I'm going to go into a little detail, and then state my question.

I have 2 entities: A Mineral, and a MineralElement.

Mineral has a name, and a 1 to many relationship with MineralElement called formula. MineralElement has some basic properties.

Now, what I am trying to do:
I have a NSTableView that lists all the minerals in a document. I have another view would allow the user to add or remove mineral elements from the selected Mineral (ie. edit their formula). I have set up 2 NSArrayControllers, one for the Minerals, and one for the MineralElements in the currently selected Mineral. I have tried to bind the content of the MineralElement NSArrayController to the current selection in Minerals NSArrayController (model key path is formula).

It doesn't work, does anybody know how to do this?

(To summarize, I want to be able to edit the array within a currently selected object using bindings, is it possible to do it graphically, or am I going to have to code this?)
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
May 15, 2005, 09:59 PM
 
This sounds more like a bindings problem than a CoreData problem.

Should be fairly straightforward to set up the bindings for this. But it's not easy to explain. Have you been throught any of the bindings tutorials around?
     
11011001  (op)
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
May 16, 2005, 10:44 PM
 
Originally Posted by Brass
This sounds more like a bindings problem than a CoreData problem.

Should be fairly straightforward to set up the bindings for this. But it's not easy to explain. Have you been throught any of the bindings tutorials around?
Yes I've been through the tutorials, I know how to do the simple things, but I can't find out how to do this, or what little thing I might be doing wrong.
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
May 17, 2005, 12:11 AM
 
It's difficult to help without knowing in great detail how you've configured your NSArrayController objects. I'll try to give a summary of some things to check, but it's not exhaustive...

• For the top-level NSArrayController (mineral), what is it's contentArray binding set to? OR what is it's content outlet set to? Does the table for mineral work OK?

• For the bottom-level NSArrayController (element), is it's contentArray bound to the mineral array controller's selected object? If so, what model key path is it bound to? Does this return an NSArray?

• For both NSArrayControllers, what is the Object Class Name set to? Is this the class that all objects within the array are instances of?

You need to provide this kind of detail before any useful help can be offered, I think.

Good luck.
     
11011001  (op)
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
May 18, 2005, 10:11 AM
 
I am using entities and I have set the entity names correctly. I could and have got this working just find using regular bindings, but I am trying to work within the Core Data framework (all that managed object stuff sure looks yummy).

So anyways, I'm using the xcdatamodel thingy to establish the relationships between my objects. The controller for the mineral array works just fine, I just can't seem to get the element array to bind correctly to the formula key path for the currently selected mineral. I am assuming that because I have establish a one to many relationship for formula (that is a relationship from a single mineral, to many elements) that this should just work. It seems to me that I am not understanding something here though. I'm going to play more and try to clarify my issue more precisely.
     
11011001  (op)
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
May 18, 2005, 11:03 AM
 
It was a simple solution.

In my MineralElement NSArrayController I bound contentSet to the Mineral NSArrayController, with a key path of formula. The thing I was missing was the managed object context. I kept thinking that this should be from the MineralElement NSArrayController, but it really needed to come from my File Owner (an NSPersistentDocument). It's so obvious now >.<
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:31 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,