Re: Dependent Keys
Re: Dependent Keys
- Subject: Re: Dependent Keys
- From: Jim Hamilton <email@hidden>
- Date: Wed, 17 Aug 2005 16:58:01 -0400
On Aug 17, 2005, at 4:08 PM, Marcus S. Zarra wrote:
Thank you, that is the answer I was looking for and unfortunately
expecting. Could you by chance point me in the right direction
where I can find out more about how to implement the second option
you mentioned?
see below.
On 8/17/05, Jim Hamilton <email@hidden> wrote:
On Aug 17, 2005, at 1:59 PM, Marcus S. Zarra wrote:
> I am trying to set up a dependent key that is dependent on the value
> stored inside of a child object. Specifically, assuming I have the
> following two objects in Core Data:
>
> Parent<-->>Child
>
> Inside of the child object is a field called "value". In the
parent I
> want to update a dependent key based on changes to this value.
In the
> parent's initialize method I have placed the following code:
>
> + (iniitalize) {
> NSArray *keys = [NSArray arrayWithObjects:@"children.value", nil];
> [self setKeys:keys
> triggerChangeNotificationsForDependentKey:@"dependent"];
> }
>
> The issue is that whenever I change the child's value the dependent
> key is not being fired/called.
>
> Two questions:
>
> 1. Is this possible?
Yes
> Can I use the dependent key notification with a keyPath?
No
> 2. If it is possible, what am I doing wrong?
As you have discovered, what you're doing wrong is trying to use
dependent key notification with a keyPath.
There are two approaches I've looked at:
1) Register Parent for KVO notifications for each Child
2) Register for the notification
NSManagedObjectContextObjectsDidChangeNotification, and filter out
changes that are not a particular Parent's Child instances.
<http://developer.apple.com/documentation/Cocoa/Reference/
CoreData_ObjC/Classes/NSManagedObjectContext.html#//apple_ref/doc/uid/
TP30001182-237802>
NSManagedObjectContextObjectsDidChangeNotification's userInfo
dictionary contains three sets of objects. An object that depends on
attributes of other objects can iterate them, looking for the objects
whose changes should propagate through.
Jim H
--
Jim Hamilton
email@hidden
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