I have a NSMutableArray, which I need to chance its values, but I have this error:
[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x5291db0
This is the declaration of my NSMutableArray:
NSMutableArray *selectedOptions = [NSArray arrayWithObjects:[NSNumber numberWithInteger:0], nil];
Then, I’m using replaceObjectAtIndex method, of this way:
[self.selectedOptions replaceObjectAtIndex:0 withObject:[NSNumber numberWithInteger:1]];
But I get, that error, and I’m using NSMutableArray.
Thanks
You need to initialize your
NSMutableArrayby doingBy initializing it with
NSArray, you can no longer use therepalceObjectAtIndex:withObject:method and that’s the cause of your problem.After initializing your
NSMutableArraywith the line above, simply add objects to it with theaddObjectmethod.