-1

I am unsure why I get this error when I run my program a certain way.

2014-05-15 16:19:28.932 Puzzle[1002:f803] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInternalInconsistencyException> -[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object

I have an NSMutableArray called 'levelsCompleteArray' that I am trying to cycle through to see when the first NO, (or 0) appears and to set that iteration to a variable called 'picIndex'. If there are no YES's in the array, then the program works fine. When there is one in the next iteration, however, I get the message posted above. Does anyone know why? Code below:

[levelsCompleteArray replaceObjectAtIndex:picIndex withObject:[NSNumber numberWithBool:YES]];

BOOL wonLevel=NO;

int i=picIndex;

while (wonLevel==NO)
{
    BOOL status =[[levelsCompleteArray objectAtIndex:i] boolValue];
    if (status==1) 
    {
        i=i+1;
        if(i==3)
        {
            picIndex=0;
            wonLevel=YES;
        }
    }
    else
    {
        picIndex=i;
        wonLevel=YES;
    }
} 
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
user1633930
  • 61
  • 1
  • 2
  • 10

1 Answers1

0

It looks like levelsCompleteArray is an NSArray which is immutatable. To turn it into a mutable array try this:

NSMutableArray* mutableLevelsCompleteArray = [[NSMutableArray alloc] initWithArray:levelsCompleteArray];
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • I'll try that now. levelsCompleteArray is declared as such though: @property (nonatomic, retain) NSMutableArray *levelsCompleteArray; I believe something in my code is changing it to be immutable. – user1633930 May 15 '14 at 21:20
  • That worked. Thank you. I'm still unsure why it changed to a immutable array but I'll dig into that more. – user1633930 May 15 '14 at 21:32