我运行一个 for 来选择要删除的对象。在我删除一个应用程序崩溃后。我读到由于索引的原因,我无法删除 for 中的对象,所以我将它们删除到外面,但它仍然崩溃。当它在运行时崩溃时,它说它是一个 NSArray 而不是,它是一个 NSMutablearray。任何人都知道为什么会这样?
这是代码:
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];