I get this error once in a while when my program is running. Most of the time, the app works fine, but every now and then the app will crash and point to the second line in the for loop saying:
Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection was mutated while being enumerated.'
for(int i = 1; i <= 121; i++) {
NSLog(@"%i", i);
[(UIButton *)[self.view viewWithTag:i] setImage:[UIImage imageNamed:@"hexagon"] forState:UIControlStateNormal];
}
What do I do to avoid my program from crashing??