I run a for to choose which objects to remove. After i removed one the app crashes. I´ve read that i couldn´t remove an object in the for because of the index, so i remove them outside but it still crashes. When it crashes at runtime it says the array it is an NSArray which is not, it is a NSMutablearray. Anyone knows why is this happening?
Here is the code:
NSMutableArray *discardedItems = [NSMutableArray array];
NSInteger catalogo = [[tmpDic objectForKey:@"catalogo"] intValue];
NSInteger documento = [[tmpDic objectForKey:@"documento"] intValue];
for (i=0; i<[self.deletedDocuments count] ; i++)
{
if ([[[self.deletedDocuments objectAtIndex:i] objectForKey:@"documento"] intValue] == documento &&
[[[self.deletedDocuments objectAtIndex:i] objectForKey:@"catalogo"] intValue] == catalogo)
[discardedItems addObject:[self.deletedDocuments objectAtIndex:i]];
}
NSLog(@"Dictionary\n%@", self.deletedDocuments);
if (discardedItems != nil)
[self.deletedDocuments removeObjectsInArray:discardedItems];