Bindings, Core Data, and memory
Bindings, Core Data, and memory
- Subject: Bindings, Core Data, and memory
- From: "Andrew R. Kinnie" <email@hidden>
- Date: Tue, 27 Mar 2007 20:41:21 -0400
Greetings:
I have a Core Data document based app I am working on in order to
learn the technology better. My app has a number of entities, and
one of them has an attribute (call it quality) that is a number
between 0 and 4, which represent basically ratings lowest to highest.
I have an interface, basically master-detail wherein the user can
choose an object of this entity in a tableview, and the attributes of
the selected MO will appear below. I want the numerical attribute to
be changeable in an NSPopupButton, populated with an array of
strings, basically "lowest, low, med, high, highest" or some such.
My thought is to have this bound to an array with these strings,
where the index of the array would correspond to the numerical value
represented by the string:
0 = lowest
1 = low
2 = med
3 = high
4 = highest
i.e. the user has selected the managedObject in the "master
interface" and wants to change the "quality" attribute by changing
the popUpButton in the "detail" interface. The Popup is bound to the
array of strings (currently via an NSArrayController), and the
selectedIndex for the particular string (e.g. "lowest") should be
sent to the managedObject's attribute "quality" but the descriptive
string is really relevant only to the user, while the index will
actually become the quality attribute's value and will be used in
various calculations in other parts of the app.
Now I realize there are ways to hard-code this, I am just trying to
see if there is an ideal Core Data way to do that that doesn't feel
like a hack, and I'm trying to use this as a method to better
understand Core Data and Bindings.
I tried creating an array in myDocument and initializing it in
myDocument's -init method,
then binding the array to an arrayController's contentArray binding,
then binding the popUp's content binding to the arrayController's
arrangedObjects key, and
binding the popUp's selectedIndex binding to the entity's
arrayController's selection.quality key
This seems to work in that it doesn't explode, and I can save the
data, and the data seems to reflect the change. . . I've looked at
the generated .xml file after saving it. However, when I re-run the
app, and load the recently saved data, I get:
EXC_BAD_ACCESS
on the creation of the array in myDocument's init method. CFRetain
apparently. So evidently, I am missing something.
Eventually, I'd also like to know how to have the app import data
from an external source (e.g. an xml file), or userDefaults or some
such and use that data as default values in my app. e.g. the user
could create (in another app or even a text file) a series of data
items which would be read into the Core Data app at launch, an be
used as the available choices for the values in some of the
attributes. This sounds like a custom validation thing, combined
with Cocoa's xml parser perhaps. In any event, I think this prevents
using an NSValueTransformer, though I may be able to use it in this
limited case.
But for now getting this much to work would be nice.
Thanks in advance,
Andrew
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden