title: Implementing NSFastEnumeration on Custom Class
body: <p>I have a class that inherits from NSObject. It uses an NSMutableArray to hold children objects, e.g. People using NSMutableArray *items to hold Person objects. How do I implement the NSFastEnumerator on items?</p>
  
  <p>I have tried the following but it is invalid:</p>
  
  <pre><code>@interface People : NSObject &lt;NSFastEnumeration&gt;
  {
      NSMutableArray *items;
  }
  </code></pre>
  
  <p>@implementation ...</p>
  
  <pre><code>- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
  {
      if(state-&gt;state == 0)
      {
          state-&gt;mutationsPtr = (unsigned long *)self;
          state-&gt;itemsPtr = items;
          state-&gt;state = [items count];
          return count;
      }
      else
          return 0;
  }
  </code></pre>