views:

89

answers:

1

Overall I'm loving Core Data so far, but there is one quirk in the system that I keep coming back to, and that's problems created when I decide to use relationships instead of attributes.

Using cars for an example, let's say I have a Car entity and a Manufacturer entity. Ideally, I can just put a relationship between them, many cars to one manufacturer, and then when I'm setting up the edit page for the cars have the manufacturers fed into an NSPopUpButton for the user to select. This works, but it doesn't seem to save any value, so when I reload the edit page for that particular car the manufacturer appears blank.

Another alternative that saves the data is to treat the manufacturer as an attribute, and then set the form up the same as before (manufacturer names fed into an NSPopUpButton list). This consistently saves the manufacturer in the car's data, but no inverse relationship is created connecting back to the manufacturer, which is less than ideal.

How do you use relationships and attributes most effectively in Core Data? Further, how do you resolve issues like the one outlined above so that the connections are made, but the names of the linked items are displayed instead of "No Data" or fault notices?

+1  A: 

Have you seen this problem only with your NSPopUpButton user interface? It's possible you haven't configured your bindings correctly. In Core Data, it's enough to assign an instance of the appropriate entity to a relationship. You won't need a separate attribute to store the relationship.

The first thing I'd check is that the selectedObject binding is bound to the correct relationship.

Alex

related questions