*** Collection
2019-06-06  本文已影响0人  OwenWong

这个错误提示是说:遍历数组的同时又修改了这个数组里面的内容,因此导致崩溃。

处理方法一:

for in 改成常规for循环

处理方法二:

定义一个一模一样的数组,便利数组A然后操作数组B

    NSMutableArray * arrayTemp = xxx; 
    NSArray * array = [NSArray arrayWithArray: arrayTemp];  
    for (NSDictionary * dic in array) {        
        if (condition){            
            [arrayTemp removeObject:dic];
        }       
    }

处理方法三:

使用enumerate方法遍历

NSMutableArray *tempArray = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
    [tempArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj isEqualToString:@"34"]) {
           *stop = YES;
            if (*stop == YES) {
                [tempArray replaceObjectAtIndex:idx withObject:@"6"];
            }
        }

        if (*stop) {
            NSLog(@"array is %@",tempArray);
        }
    }];

处理方法四:

for in 改用while

while (self.subviews.count) {
        UIView* child = self.subviews.lastObject;
        [child removeFromSuperview];
    }

上一篇 下一篇

猜你喜欢

热点阅读