Okay, coming from a perl background I am used to Arrays holding refs to Hashes (Dictionary in iPhone parlance).
What I would like to know is this: If I have a NSArray of NSMutableDictionaries. Say I added the following NSMutableDictionary to an NSArray:
[theArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys: timestamp, @"timestamp" ,name, @"name" ,lat, @"lat" ,lon, @"lon" , nil]];
Then later I cycled through the array like so:
for (NSMutableDictionary theDict in theArray)
{
}
does each theDict
represent a pointer NSMutableDictionary's data such that I can do this:
for (NSMutableDictionary *theDict in theArray)
{
if ([theDict objectForKey:@"timestamp"] != nil && [[theDict objectForKey:@"timestamp"] isEqualToString:@"timestamp"])
{
[theDict setObject:@"new name" forKey@"name"];
}
}
and then expect theArray
to hold the changed value throughout the life of theArray?
or, do I need to do this:
int ct = 0;
for (NSMutableDictionary *theDict in theArray)
{
if ([theDict objectForKey:@"name"] != nil && [[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;
}
It cannot be all that code, can it? -- just to replace one value for a key of a NSMutableDictionary held in an NSArray?
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.