I have a NSMutableArray with five objects. I want to remove two objects when a certain condition is fulfilled. But it is giving me an error-----* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 3 beyond bounds [0 .. 2]' Here is my code
-(IBAction)buttonPressed1:(id)sender{
for (int i = 0; i < [objectArray1 count]; i++) {
if ([[objectArray1 objectAtIndex:3] isEqualToString:@"xyz"])
{
NSMutableIndexSet *indexes = [NSMutableIndexSet indexSetWithIndex:3];
[indexes addIndex:4];
[objectArray1 removeObjectsAtIndexes:indexes];
NSLog(@"Hello %@",objectArray1 );
}
}
IF I remove for{} condition it is working fine. Any help will be appreciated.