title: iPhone ... If you have an NSArray of NSMutableDictionaries, does the Array hold a ref to the dict or a "copy"?
body: <p>Okay, coming from a perl background I am used to Arrays holding refs to Hashes (Dictionary in iPhone parlance).  </p>
  
  <p>What I would like to know is this:  If I have a NSArray of NSMutableDictionaries.  Say I added the following NSMutableDictionary to an NSArray:</p>
  
  <pre><code>[theArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys: timestamp, @"timestamp" ,name, @"name" ,lat, @"lat" ,lon, @"lon" , nil]];
  </code></pre>
  
  <p>Then later I cycled through the array like so:</p>
  
  <pre><code>for (NSMutableDictionary theDict in theArray)
  {
  
  }
  </code></pre>
  
  <p>does each <code>theDict</code> represent a pointer NSMutableDictionary's data such that I can do this:</p>
  
  <pre><code>for (NSMutableDictionary *theDict in theArray)
  {
        if ([theDict objectForKey:@"timestamp"] != nil &amp;&amp; [[theDict objectForKey:@"timestamp"] isEqualToString:@"timestamp"])
        {
             [theDict setObject:@"new name" forKey@"name"];
        }   
  }
  </code></pre>
  
  <p>and then expect <code>theArray</code> to hold the changed value throughout the life of theArray?</p>
  
  <p>or, do I need to do this:</p>
  
  <pre><code>int ct = 0;
  for (NSMutableDictionary *theDict in theArray)
  {
        if ([theDict objectForKey:@"name"] != nil &amp;&amp; [[theDict objectForKey:@"name"] isEqualToString:@"name you want to change"])
        {
             NSMutableDictionary *tmpDict = [[NSMutableDictionary alloc] initWithDictionary:theDict copyItems:YES];
             [tmpDict setObject:@"new name" forKey@"name"];
             [theDict replaceObjectAtIndex:ct withObject:tmpDict];
             [tmpDict release];
             break;
        }
        ct += 1;
  }
  </code></pre>
  
  <p>It cannot be all that code, can it? -- just to replace one value for a key of a NSMutableDictionary held in an NSArray?</p>
  
  <p>Sorry if this question is obvious to some...but still trying to wrap my mind around pointer to a dictionary (or object) in Objective-c -- with is roughly equivalent to a ref to a hash in perl -- vs a copy (or deepcopy) of an object in Objective-c.  And the problem is made more confusing by the NSArray holding the pointers (hopefully) to the NSMutableDictionaries.  This is how it is done in perl -- and from what I am understanding -- outside of the name (pointer vs reference) .. it is the same in Objective-c.</p>