0
votes

I have this value inside my NSMutableArray called myMutableArray:

(
     {
     "name_user" = xxxxxx;
     "user_key" = "xxxxxxx";
     }

Believing that within this array there is a dictionary (as seen above), let's assume I wanted to add another dictionary in this array to stay with a similar result like this:

 (
         {
         "name_user" = xxxxxx;
         "user_key" = "xxxxxxx";
         },
         {
         "name_user" = aaaaaa;
         "user_key" = "stack overflow";
         }

For that I'm testing the following code:

[myMutableArray addObject:@[@{@"name_user":"stack overflow",@"user_key":@"aaaaaa"}]];

The problem with this code is that I'm getting the following error message:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'

How can I solve this problem?

1
Your myMutableArray is actually referencing an NSArray, not an NSMutableArray. Where do you create this array?Paulw11
@Paulw11, I create him with a code thats converter a json file to an array...Lacrifilm
Paulw11 is not asking for an english language description of literally where you create the code! He's asking for you to post the code!!Gruntcakes
NSJSONReadingMutableContainersSteven Fisher

1 Answers

1
votes

Just because you have an attribute of a mutable type doesn't mean the instance it points to is mutable, you're telling the compiler it will be at runtime but there's no guarantee if you write the code differently.

So, you should check how you create the array to make it mutable, or create a mutable copy before you try to mutate it.