title: With NSPointerArray, how to iterate over opaque pointers?
body: <p>I recently discovering these classes like <code>NSMapTable</code> and <code>NSPointerArray</code>, which work like the traditional collections, but also let you store weak references or plain old C pointers.  Unfortunately it looks like you can't use the <code>for...in</code> syntax to iterate over non-<code>NSObject</code> pointers.  For example:</p>
  
  <pre><code>typedef struct Segment {
      CGPoint bottom, top;
  } Segment;
  ...
  NSPointerArray *segments = [[NSPointerArray alloc] 
                                   initWithOptions:NSPointerFunctionsOpaqueMemory];
  ...
  Segment *s = malloc(sizeof(Segment));
  [segments addPointer: s];
  ...
  for (Segment *s in segments) {   // nope...
  </code></pre>
  
  <p>The compiler does not like that last line. The error:</p>
  
  <blockquote>
    <p>Selector element type 'Segment *' (aka 'struct Segment *') is not a valid object</p>
  </blockquote>
  
  <p>So, do I need to do this?</p>
  
  <pre><code>for (int i=0, len=segments.count; i&lt;len; i++) {
      Segment *seg = [segments pointerAtIndex:i];
      ...
  </code></pre>
  
  <p>That's not the end of the world, but I just want to make sure. </p>