Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: replace an object inside an array of array

My code is:

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


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

indexSelected is an int and new is 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?

like image 238
cyclingIsBetter Avatar asked Apr 19 '26 02:04

cyclingIsBetter


1 Answers

This is because NSArray is immutable. Use an NSMutableArray.

like image 72
Joshua Smith Avatar answered Apr 20 '26 14:04

Joshua Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!