title: iPhone/Objective-C array enumeration crashes
body: <p>This is a bit complex.</p>
  
  <p>I've created an array (NSArray) called pointsOfInterest.</p>
  
  <p>The elements of this array are NSDictionary objects. Each dictionary has two keys, "headerTitle" and "rowObjects." The value for "headerTitle" is a simple NSString; the object for "rowObjects" is another NSArray of objects; each of these is a custom class.</p>
  
  <p>See the code below.</p>
  
  <pre><code>for (NSDictionary *dict in pointsOfInterest) {
      NSArray *keys = [dict allKeys];
      for (NSString *key in keys) {
          //NSLog(@"Key %@",key);
      }       
      NSString *category = [dict valueForKey:@"headerTitle"];
      [poiCategories addObject:category];
  }
  </code></pre>
  
  <p>So, I'm enumerating through the array, getting individual dictionary objects into dict. I then run through all of its keys - if I uncommented the NSLog line, it would display something like this:</p>
  
  <pre><code>2010-08-06 14:00:17.236 TourGuide[4479:207] Key headerTitle
  2010-08-06 14:00:17.237 TourGuide[4479:207] Key rowObjects
  2010-08-06 14:00:17.238 TourGuide[4479:207] Key headerTitle
  2010-08-06 14:00:17.239 TourGuide[4479:207] Key rowObjects
  </code></pre>
  
  <p>It then constructs a new, flat array, containing the values from all of the "headerTitle" keys. </p>
  
  <p>First, I'm well aware that I should be able to do this:</p>
  
  <pre><code>poiCategories = [[pointsOfInterest valueForKey:@"headerTitle"] retain]
  </code></pre>
  
  <p>And get the values for the various "headerTitle" keys. Doing that, however, crashes the app. What's weird, is that the above for construct works fine... IF I leave in the internal for loop. If I remove that for loop, and its useless NSLog, leaving just this:</p>
  
  <pre><code>for (NSDictionary *dict in pointsOfInterest) {
      NSString *category = [dict valueForKey:@"headerTitle"];
      [poiCategories addObject:category];
  }
  </code></pre>
  
  <p>Then it crashes. It does not grace me with any kind of trappable error that I can find. </p>
  
  <p>Any reason anyone can think of?</p>