1
votes

could you please help me to solve the following error:

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

array_Info = [[NSMutableArray alloc] init];
array_Info = [dict_Temp objectForKey:@"Children"];

NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:self.array_Info];

            int ran, arrayIndexing = 0;
            while ([temp count] != 0)
            {
                ran = arc4random();
                if(ran < 0)
                    ran*=-1;
                ran = ran % [temp count];

                if([temp count] == 1)
                    ran = 0;

                NSLog(@"%d  %d",arrayIndexing,ran);

                [self.array_Info replaceObjectAtIndex:arrayIndexing withObject:[temp objectAtIndex:ran]];

                [temp removeObjectAtIndex:ran];
                arrayIndexing++;
            }
2

2 Answers

6
votes

Presuming that array_Info is the backing variable for the self.array_Info property, you should change your second line to:

array_Info = [[dict_Temp objectForKey:@"Children"] mutableCopy];

This will give you the mutable array you need for the replaceObjectAtIndex:withObject: call.

2
votes

It seems that self.array_Info is an immutable array. Make it mutable.