title: Observing changes of derived properties: CALayer KVO example
body: <p>Is there a way to observe changes in derived properties?  For example, I want to know when a CALayer has been added as a sublayer so that I can adjust its geometry relative to its (new) parent.</p>
  
  <p>So, I have a subclassed CALayer, say CustomLayer, and I figured I could register an observer  for the property in init:</p>
  
  <pre><code>[self addObserver:self forKeyPath:@"superlayer" options:0 context:nil]
  </code></pre>
  
  <p>and implement <code>observeValueForKeyPath:ofObject:change:context</code>.  Nothing ever happens because, presumably, superlayer is a derived property (the attr dictionary stores an opaque ID for the parent).  Similarly, I can't subclass <code>setSuperlayer:</code> because it is never called.  In fact, as far as I can tell there are no instance methods called or public properties set on the sublayer when a parent does <code>[self addSublayer:aCustomLayer]</code>.  </p>
  
  <p>Then I thought, OK, I'll subclass addSublayer like this:</p>
  
  <pre><code>- (void)addSublayer:(CALayer *)aLayer {
      [aLayer willChangeValueForKey:@"superlayer"];
      [super addSublayer:aLayer];
      [aLayer didChangeValueForKey:@"superlayer"];
  }
  </code></pre>
  
  <p>but still nothing!  (Perhaps it's a clue that when I make a simple standalone test class and use the <code>will[did]ChangeValueForKey:</code> then it works.)  This is maybe a more general Cocoa KVO question.  What should I be doing?  Thanks in advance!</p>