title: Block-Based NSNotificationCenter Observing With Subclasses?
body: <p>I have a class <code>Poster</code> which posts notifications through the <code>NSNotificationCenter</code>. I have two different observers: <code>ObserverSuperclass</code> and <code>ObserverSubclass</code>. <code>ObserverSuperclass</code> is the superclass of <code>ObserverSubclass</code>. I'd like each class to respond differently to the notification.</p>
  
  <p>According to <a href="http://nshipster.com/nsnotification-and-nsnotificationcenter/" rel="nofollow">NSHipster</a>, I should use the modern block-based api: <code>addObserverForName:object:queue:usingBlock:</code>. </p>
  
  <p>In <code>ObserverSubclass</code>'s initialization method, I need to remove the superclass as an observer. Because I'm using the block-based API, I need to reference the return value of <code>addObserverForName:object:queue:usingBlock:</code> - an "opaque object to act as the observer". So I write the following code:</p>
  
  <p>In <code>ObserverSuperclass.h</code></p>
  
  <p><code>@property (nonatomic, strong) id observer;</code></p>
  
  <p>In <code>ObserverSuperclass.m</code></p>
  
  <p><code>self.observer = [NSNotificationCenter defaultCenter] addObserverForName:@"Help!" object:nil queue:nil usingBlock:^{old block}];</code></p>
  
  <p>In <code>ObserverSubclass.m</code></p>
  
  <p><code>[[NSNotificationCenter defaultCenter] removeObserver:self.observer name:@"Help!" object:nil];</code></p>
  
  <p><code>self.observer = [NSNotificationCenter defaultCenter] addObserverForName:@"Help!" object:nil queue:nil usingBlock:^{new block}];</code></p>
  
  <p>Is this actually the best way to do this? I'm not sure it makes sense to use the block-based API here. </p>