Re: KVO / Core Data question
Re: KVO / Core Data question
- Subject: Re: KVO / Core Data question
- From: "Paul L. Gribble" <email@hidden>
- Date: Thu, 15 Dec 2005 11:42:03 -0500
- Thread-topic: KVO / Core Data question
I tried in the init method of my Trip entity, binding the
"transactionBalance" attribute of my "Trip" entity to the
"email@hiddent" (transaction is another entity, Trip is connected
to it using a to-many relationship)
NSMutableDictionary * options;
options = [NSMutableDictionary new];
[self bind:@"transactionBalance" toObject:self
withKeyPath:@"email@hiddent"
options:options];
[options release];
but I get an error message at runtime about not being KVC compliant:
[Session started at 2005-12-15 11:34:34 -0500.]
2005-12-15 11:34:35.013 UWOTrips[2028] An uncaught exception was raised
2005-12-15 11:34:35.013 UWOTrips[2028] [<Trip 0x3c07c>
addObserver:<NSObjectParameterBinder 0x3a7700>
forKeyPath:@"email@hiddent" options:0x0 context:0x0] was sent to
an object that is not KVC-compliant for the "transaction" property.
2005-12-15 11:34:35.014 UWOTrips[2028] *** Uncaught exception:
<NSUnknownKeyException> [<Trip 0x3c07c> addObserver:<NSObjectParameterBinder
0x3a7700> forKeyPath:@"email@hiddent" options:0x0 context:0x0] was
sent to an object that is not KVC-compliant for the "transaction" property.
My guess is I'm not doing something obvious - but I am having trouble
finding a good set of tutorials on using core data & KVC together
>
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/i
>
ndex.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>
--
Paul L. Gribble, Ph.D.
Assistant Professor
Dept. Psychology
University of Western Ontario
London, Ontario
Canada N6A 5C2
Tel. +1 519 661 2111 x82237
Fax. +1 519 661 3961
email@hidden
http://bubba.ssc.uwo.ca
_______________________________________________
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