Re: Composite values using Core Data and Cocoa Bindings
Re: Composite values using Core Data and Cocoa Bindings
- Subject: Re: Composite values using Core Data and Cocoa Bindings
- From: "Marcus S. Zarra" <email@hidden>
- Date: Wed, 27 Jul 2005 11:55:11 -0600
setKeys:triggerChangeNotificationsForDependentKey; is what I was
referring to in the last section of my comments. Although it is
interesting that exposeBinding is not required. I will have to play
with that further.
On 7/27/05, mmalcolm crawford <email@hidden> wrote:
>
> On Jul 27, 2005, at 8:48 AM, Marcus S. Zarra wrote:
> > On 7/26/05, Andy Shamel <email@hidden> wrote:
> >> I'm having a heck of a time figuring out how to get a value into an
> >> NSTextField that is the sum or product of two or more attributes in
> >> separate entities. For example, I have a character entity with
> >> several ability scores as Int 16 attributes. Each of these scores can
> >> be modified by a number of other entities. How do I make the
> >> NSTextField display the sum of the original score, plus any
> >> modifiers?
> >>
> > I would create a subclass of NSManagedObject for the object in
> > question.
> > Then create an accessor method that does the calculation for you.
> > Then you
> > can link the NSTextField to that accessor method.
> >
> Yes, this is standard Cocoa practice for calculating derived values
> (for a Core Data-specific example, see <http://pubsbuild.apple.com/
> trains/Web/documentation/Cocoa/Conceptual/
> NSPersistentDocumentTutorial/03_CustomClass/chapter_4_section_3.html).
>
> > To get this to auto update you need to [self exposeBinding:] in the
> > initialize method of the new NSManagedObject subclass and then set
> > it to
> > trigger on the other values it calculates off of.
> >
> No! I'm not sure why you might think this is the right thing to do?
>
> exposeBinding: is a method views and controllers use, and is
> typically only useful if you want to put one of these objects in an
> Interface Builder palette.
>
> If you need to register a dependency on other keys in your own class,
> then use the KVO method
> setKeys:triggerChangeNotificationsForDependentKey:. If, as seems to
> be the case here, you need to track changes in other, related,
> objects then you must either observe those objects (using KVO) or
> register as an observer of
> NSManagedObjectContextObjectsDidChangeNotifications for your managed
> object context and react to changes to those related objects.
>
> mmalc
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden