title: Observing Changes to a mutable array using KVO vs. NSNotificationCenter
body: <p>In my model I have an array of objects called events. I would like my controller to be notified whenever a new object is added to events.</p>
  
  <p>I thought that a good way to do this would be use the KVO pattern to get notified when the events changes (from a new object being added)</p>
  
  <pre><code>// AppDelegate
  // events is a NSMutableArray @property/@synthesize etc...
  
  [appDelagate addObserver:self
                 forKeyPath:@"events"
                    options:NSKeyValueObservingOptionNew
                    context:NULL];
  </code></pre>
  
  <p>But the <em>observeValueForKeyPath</em> method wasn't being called and I discovered that Arrays are not KVO compliant :-(</p>
  
  <p>One option is to manually trigger the method by calling <em>willChangeValueForKey</em> for the keyPath</p>
  
  <pre><code>// ViewController
  [self willChangeValueForKey:@"events"];
  [self.events addObject:event];
  [self didChangeValueForKey:@"events"];
  </code></pre>
  
  <p>But this feels heavy since I should probably also keep track of the before and after state of my events array so that it can be accessed from the <em>observeValueForKeyPath</em> method.</p>
  
  <p>One approach could be to use a standard array (instead of mutable) and create/set a new instance of events each time I want to add an new object, or I could make a separate property that keeps track of how many items are in the mutable array (I wish you could observe @"events.count" ).</p>
  
  <p>Another option would be to use NSNotificationCenter. I've also read some answers that suggest using blocks (but I have no idea where to start on that).</p>
  
  <p>Finally, could I keep an instance of my controller in my delegate and just send a relevant message?</p>
  
  <pre><code>// Delegate
  [myController eventsDidChange];
  </code></pre>
  
  <p>Is it odd to keep a reference to a controller from a delegate?</p>
  
  <p>I'm struggling to understand how to choose which is the best approach to use, so any advice on performance, future code flexibility and best practices is greatly appreciated!</p>