• 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: Dependent Keys
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Dependent Keys
      • From: Bill Cheeseman <email@hidden>
References: 
 >Dependent Keys (From: "Marcus S. Zarra" <email@hidden>)
 >Re: Dependent Keys (From: Jim Hamilton <email@hidden>)
 >Re: Dependent Keys (From: "Marcus S. Zarra" <email@hidden>)

  • Prev by Date: Re: Want to get filename for images dragged from Finder and from Safari / Firefox
  • Next by Date: Re: NSApplicationMain() doesn't set NSApp to my subclass
  • Previous by thread: Re: Dependent Keys
  • Next by thread: Re: Dependent Keys
  • Index(es):
    • Date
    • Thread