title: Error when using NSMutableSet
body: <p>I get the error </p>
  
  <blockquote>
    <p><strong>* Terminating app due to uncaught exception 'NSGenericException', reason: '*</strong> Collection &lt;__NSCFSet: 0x6b66390> was mutated while being enumerated.'</p>
  </blockquote>
  
  <p>when adding an new delegate to my class. Or at least, that's where I think the problem is. </p>
  
  <p>This is my code: MyAppAPI.m</p>
  
  <pre><code>[...]
  static NSMutableSet *_delegates = nil;
  
  @implementation MyAppAPI
  
  + (void)initialize
  {
      if (self == [MyAppAPI class]) {
          _delegates = [[NSMutableSet alloc] init];
      }
  }
  
  + (void)addDelegate:(id)delegate
  {
      [_delegates addObject:delegate];
  }
  
  + (void)removeDelegate:(id)delegate
  {
      [_delegates removeObject:delegate];
  }
  [...]
  
  @end
  </code></pre>
  
  <p>MyAppAPI is a singleton which I can use throughout my application. Wherever I can (or should be able to) do: <code>[MyAppAPI addDelegate:self]</code>.<br/>
  This works great, but only in the first view. This view has a UIScrollView with PageViewController which loads new views within itself. These new views register to MyAppAPI to listen to messages until they are unloaded (which in that case they do a <code>removeDelegate</code>).
  However, it seems to me that it dies directly after I did a addDelegate on the second view in the UIScrollView.<br/>
  <br/>
  How could I improve the code so that this doesn't happen?</p>
  
  <p><strong>Update</strong><br/>
  I'd like to clarify me a bit further.
  What happens is that view controller "StartPage" has an UIScrollView with a page controller. It loads several other views (1 ahead of the current visible screen).
  Each view is an instans PageViewController, which registers itself using the addDelegate function shown above to the global singleton called MyAppAPI. 
  However, as I understand this viewcontroller 1 is still reading from the delegate when viewcontroller 2 registers itself, hence the error shows above.</p>
  
  <p>I hope I made the scenario clear. I have tried a few things but nothing helps.
  I need to register to the delegate using addDelegate even while reading from the delegates. How do I do that?</p>
  
  <p><strong>Update 2</strong>
  This is one of the reponder methods:</p>
  
  <pre><code>+ (void)didRecieveFeaturedItems:(NSArray*)items
  {   
      for (id delegate in _delegates)
      {
          if ([delegate respondsToSelector:@selector(didRecieveFeaturedItems:)])
              [delegate didRecieveFeaturedItems:items];
      }
  }
  </code></pre>