So in this app that im working on, I have an NSMutableArray that holds different colors. And yet i find that the count of the array is changing at random times. Ex: I log the count when its first set, and its 5, but then when i need to compare it to something else, for some reason it is now 4. No calls have been made to the array in between those times. any ideas?
int color = arc4random() % 4;
switch (color) {
case 0:
[self.sequenceArray addObject:[[UIColor redColor] retain]];
break;
case 1:
[self.sequenceArray addObject:[[UIColor yellowColor] retain]];
break;
case 2:
[self.sequenceArray addObject:[[UIColor greenColor]retain]];
break;
case 3:
[self.sequenceArray addObject:[[UIColor blueColor] retain]];
break;
default:
break;
}
that adds a color to the sequence. So i log after that function and it counts as 5. Then I log the same statement later and it counts as 4. None of the other code sets anything in the array, just reads it to compare to numbers etc so idt its helpful Ex:
Code:
if ([[object.sequenceArray objectAtIndex:index] isEqual:[UIColor redColor]])
This is going to take a while if you only post snippets. Post everything - logs, whatever - related to that array if you want any chance of figuring out the issue.
So basically theres 8 buttons, each with a different tag. that corresponds to a color. the simon object managaes the color array, and sets it using the code i posted earlier. Any ideas? In the logs, right after continueGame is called, it is logged as 5, but when its logged during the colorPushed function, its 4.
Thx! I figured it out. really stupid mistake on my part - I called viewDidLoad after adding to the sequence, and in there it starts a new sequence. So It would be 5 then, but then go back to (which is the beginning/default) when it starts a new sequence. Thanks for your help!