Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change a value within a NSMutableArray

I have a NSMutableArray that is loaded with values.

Later in the application, I need to change the values of one of the elements in the array.

How do I accomplish this?

thanks tony

like image 782
pithhelmet Avatar asked Nov 18 '10 18:11

pithhelmet


3 Answers

Take a look at the class reference instance methods:

http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSMutableArray_Class/Reference/Reference.html

You can use:

replaceObjectAtIndex:withObject: given you know the index of the object. replaceObjectsAtIndexes:withObjects: to replace multiple objects at once.

like image 117
Evan Mulawski Avatar answered Oct 31 '22 18:10

Evan Mulawski


Call -[NSMutableArray replaceObjectAtIndex:withObject:]. Or, if the object in the array is mutable, just grab it with -objectAtIndex: and modify its properties directly.

like image 4
Ole Begemann Avatar answered Oct 31 '22 20:10

Ole Begemann


You would probably want to use 'replaceObjectAtIndex:withObject:' for replacing the object itself.

like image 1
Dylan Lukes Avatar answered Oct 31 '22 18:10

Dylan Lukes