• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Composite values using Core Data and Cocoa Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Composite values using Core Data and Cocoa Bindings


  • Subject: Re: Composite values using Core Data and Cocoa Bindings
  • From: mmalcolm crawford <email@hidden>
  • Date: Wed, 27 Jul 2005 10:43:10 -0700


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


  • Follow-Ups:
    • Re: Composite values using Core Data and Cocoa Bindings
      • From: mmalcolm crawford <email@hidden>
    • Re: Composite values using Core Data and Cocoa Bindings
      • From: "Marcus S. Zarra" <email@hidden>
References: 
 >Composite values using Core Data and Cocoa Bindings (From: Andy Shamel <email@hidden>)
 >Re: Composite values using Core Data and Cocoa Bindings (From: "Marcus S. Zarra" <email@hidden>)

  • Prev by Date: Re: Another NSDocument question
  • Next by Date: Re: Composite values using Core Data and Cocoa Bindings
  • Previous by thread: Re: Composite values using Core Data and Cocoa Bindings
  • Next by thread: Re: Composite values using Core Data and Cocoa Bindings
  • Index(es):
    • Date
    • Thread