I have an array within an (mutable) array. I am trying to replace certain objects with "replaceObjectAtIndex."
I have tried:
[[mutableArrayName objectAtIndex:0]replaceObjectAtIndex:0 withObject:@"TEST"];
but I get the following error:
-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x4e24d70 2011-03-17 17:02:07.008 Contact details[5145:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x4e24d70'
I tried this as well:
[mutableArrayName replaceObjectAtIndex:[[mutableArrayName objectAtIndex:0]objectAtIndex:0] withObject:@"TEST"];
but I get the following error:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray replaceObjectAtIndex:withObject:]: index 16660 beyond bounds [0 .. 0]'
The 2nd approach relies on having 3 arrays instead of 2. 1st approach seems to be fine but I guess you have an NSArray
inside of an NSMutableArray
because NSArray:replaceObjectAtIndex:withObject
does not exist. So ensure that all arrays are mutable.
So as far as I've understood, you have: a mutable array, and within that, you've got more arrays. Now you want to fetch one of those "sub-arrays" and modify it.
In this case the first try is the correct one, except that you've got NSArray
instances inside your NSMutableArray
. And you cannot modify those, hence the exception. So you need to make sure you're stuffing NSMutableArrays
inside your outer NSMutableArray
. Then the call of your first try will succeed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With