Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found this in the docs (<a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ModelObjects/Articles/moIntegrating.html#//apple_ref/doc/uid/TP40002138-SW6" rel="nofollow noreferrer" title="KVC Compliance - Dependent Values">KVC Compliance - Dependent Values</a>): </p> <blockquote> <p>Important: Note that you cannot set up dependencies on to-many relationships. For example, suppose you have an Order object with a to-many relationship (orderItems) to a collection of OrderItem objects, and OrderItem objects have a price attribute. You might want the Order object have a totalPrice attribute that is dependent upon the prices of all the OrderItem objects in the relationship. You can not do this by implementing keyPathsForValuesAffectingValueForKey: and returning orderItems.price as the keypath for totalPrice. You must observe the price attribute of each of the OrderItem objects in the orderItems collection and respond to changes in their values by updating totalPrice yourself.</p> </blockquote> <p><strong>So you cannot rely on KVO dependencies or notifications when there is a to-many relationship in the keypath</strong>. This applies to my array of tags, so I've added some code to patch this broken link.</p> <p>When I add a project to the "projects" array:</p> <pre><code>[newProject addObserver:self forKeyPath:@"tags" options:NSKeyValueObservingOptionNew context:nil]; </code></pre> <p>And the important part:</p> <pre><code>-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([object isKindOfClass:[CProject class]] &amp;&amp; [keyPath isEqualToString:@"tags"]) { [self willChangeValueForKey:@"projects"]; [self didChangeValueForKey:@"projects"]; } } </code></pre> <p>And to cleanup, when I remove a project:</p> <pre><code>[project removeObserver:self forKeyPath:@"tags"]; </code></pre> <p>Not sure if this is the best solution, but it's keeping my list updated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload