Search code examples
objective-cnsarray

How to modify value in NSArray object?


I want to modify value in NSArray at index 0.

Here is sample program

NSArray *test = @[@"abc",@"rec",@"myPM"];
NSLog (@"%@",[test objectAtIndex:0]);
test[0]=@"001";
NSLog (@"%@",[test objectAtIndex:0]);

Here I am getting lot of errors. please help me in this.


Solution

  • You should use an NSMutableArray

    And with this method :

    [yourArray replaceObjectAtIndex:INDEX withObject:OBJECT].