theandrew
theandrew

Reputation: 33

change object in NSMutableArray

i have a NSMutableArray. In this is the structure of my Array:

{
Distance = 0;
Name = Name1;
Town = Town1;
}
{
Distance = 0;
Name = Name2;
Town = Town2;
}

And now I want to replace "Distance". For example that "Distance = 15".

How can I do this?

Upvotes: 0

Views: 159

Answers (1)

Dr.Kameleon
Dr.Kameleon

Reputation: 22810

OK, let's say your initial NSMutableArray is called initial (given that it contains NSMutableDictionary objects...

To alter the first element's distance value :

[[initial objectAtIndex:0] setValue:[NSNumber numberWithInt:15] 
                           forKey:@"Distance"];

IF you want to perform the correction for every entry in the array, just do it this way :

for (NSMutableDictionary* entry in initial)
{
     [entry setValue:[NSNumber numberWithInt:15] 
              forKey:@"Distance"];
}

Upvotes: 1

Related Questions