0

I have a list of arrays, each of elements of these is array to. I know, it's a little freaky, but it's necessary. So, I need to replace elements of deepest array. I've tried this:

for (int i = 0; i < [myArray count]; i++) {
    for (int j = 0; j < [[myArray objectAtIndex:i] count]; j++) {
        for (int k = 0; k < [[[myArray objectAtIndex:i] objectAtIndex:j] count]; k++) {
            [[[myArray objectAtIndex:i] objectAtIndex:j] replaceObjectAtIndex:k withObject:@"Some_string"];
        }
    }
}

and got an error *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance. But I can to log this element, e.g. NSLog(@"%@", [NSString stringWithFormat:@"%@",[[[myArray objectAtIndex:0] objectAtIndex:0]objectAtIndex:0]]);, it's ok.

What it can be? Thanks for your help.

1 Answer 1

1

Are your arrays instances of NSMutableArray instead of immutable NSArray?

Sign up to request clarification or add additional context in comments.

4 Comments

Yes. I should convert it to NSMutableArray? UPDATE: I create mutable array from myArray by NSMutableArray *myMutArray = [myArray mutableCopy], but it doesn't helps.
I think the problem is that you need to have the inner arrays mutable. So instead of [myArray mutableCopy] do myMutArray = [NSMutableArray array], then go through myArray and add, for each subarray, its mutableCopy to the new myMutArray.
Sorry, little misunderstanding. myArray is instance of NSArray initially. @mrueg, ok, thanks, I'll try.
@mrueg mutableCopy is guaranteed to return a mutable instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.