Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the value of an NSMutableArray at a particular index

[array objectAtIndex:i] doesn't work as an L value, so it can't be used to set the object at index i.

like image 736
node ninja Avatar asked Oct 20 '10 20:10

node ninja


People also ask

How do you change the value of an array in Objective C?

The only way is to create a new NSArray and change your pointer to a new NSArray. I can give an example... So basically, you can create a mutable copy temporarily, make the change you need, and then make an immutable copy. Once you have the immutable copy, you can point myArray to the new copy.

What is difference between NSArray and NSMutableArray?

The primary difference between NSArray and NSMutableArray is that a mutable array can be changed/modified after it has been allocated and initialized, whereas an immutable array, NSArray , cannot.

What is NSMutableArray Objective C?

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray . NSMutableArray is “toll-free bridged” with its Core Foundation counterpart, CFMutableArray .


1 Answers

Use -insertObject:atIndex: or replaceObjectAtIndex:withObject:.

like image 197
Costique Avatar answered Nov 05 '22 00:11

Costique