PDA

View Full Version : replace value from nsmutablearray




estupefactika
Feb 23, 2009, 10:41 AM
Hi, I have a NsMutableArray, at each index there are several keys like:

Arrat:(
{
id=0;
img="xxx";
act="xxx";
},
{
...
}

...
)

I would like to replace the value for a determinate key of my array in an index. In documentation I see:

- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject

It would be easy if my array was only index no keys, but with several keys... Any Idea?



jnic
Feb 23, 2009, 10:55 AM
NSMutableDictionary (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsmutabledictionary_Class/Reference/Reference.html) is what you want.

estupefactika
Feb 23, 2009, 11:07 AM
Yes, its an array of NsMutableDictionarys, but how can I to replace? Have I to create a new nsmutabledictionary, to remove the index in array and to add the new NsMutableDictionary to this index? Only I want to replace a key for an index of array.

caveman_uk
Feb 23, 2009, 02:11 PM
If you only want to change one key at one index you could do

[[myArray objectAtIndex:i] setObject:newObject forKey:key]