IOS: replace object inside array array

My code is:

[[arrayOne objectAtIndex:indexSelected] replaceObjectAtIndex:1 withObject:new];


NSLog(@"indexSelected:%d", indexSelected); // = 0
NSLog(@"new:%@", new); // = 26

indexSelectedis an int, and newis a string

When I try to do this, I have an exception that says: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1cee60'

Why?

+3
source share
1 answer

This is because NSArray is immutable. Use NSMutableArray.

+6
source

All Articles