Re: KVO / Core Data question
Re: KVO / Core Data question
- Subject: Re: KVO / Core Data question
- From: Phil Frost <email@hidden>
- Date: Wed, 14 Dec 2005 14:03:20 -0500
On Wed, Dec 14, 2005 at 11:49:27AM -0500, Paul L. Gribble wrote:
>
I have an entity "Trip" that has a to-many relationship to another entity,
>
"Transaction" via a relationship called "transaction".
>
>
The Trip entity has a key called "balance" whose value I want to depend on
>
the sum of all of the "amount" keys of each transaction.
>
>
I understand from reading Apple's Core Data FAQ (pg. 108-109) that it's not
>
possible to do this using setKeys:triggerChangeNotificationsForDependentKey,
>
where the key would be a key-path (e.g. email@hiddent).
>
>
The FAQ suggests two solutions - one, use KVO to register the parent as an
>
observer of the relevant attribute of all the children; and one must then
>
add and remove the parent as an observer, each time child objects are added
>
to or removed from the relationship. This seems not very efficient compared
>
to the second suggestion:
>
>
register the parent with the application's notification center as an
>
observer of its managed object context. This seems like less coding to me,
>
but there are no examples. Can anyone provide, or point me to, a code
>
snippet showing how one would do this?
There is perhaps another solution: make your "balance" a transient (or
not, if you prefer) attribute. Create an observer for
"email@hiddent" and when it changes, call a method which
calculates and sets the new balance.
<
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/index.html>
I'm assuming "balance" is "email@hiddent" and something else;
if what you want is for the two to be equal, you can just bind "balance"
directly to "email@hiddent".
<
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Protocols/NSKeyValueBindingCreation_index.html>
_______________________________________________
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