1. 类型<CALayerArray: 0x17425e210> was mutated while being enumerated.
1.1 crash详情
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x17425e210> was mutated while being enumerated.'
*** First throw call stack:
(0x18fedc1c0 0x18e91455c 0x18fedbc08 0x195d1f638 0x195d1f7c0 0x195d1f688 0x195d1f7c0 0x195d1f688 0x195d2bc2c 0x195f9b5d4 0x195d32480 0x195f08464 0x196024384 0x195f07fa4 0x195ec50c4 0x195ddcd74 0x195ddc9dc 0x195ddc940 0x195d21738 0x1931ea40c 0x1931df0e8 0x1931defa8 0x19315bc64 0x1931830d0 0x195fa7b2c 0x19650c784 0x18fe8a278 0x18fe89bc0 0x18fe877c0 0x18fdb6048 0x191839198 0x195d8f818 0x195d8a550 0x1002f3e04 0x18ed985b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
1.2分析原因以及解决方案
当程序出现这个提示的时候,是因为你一边遍历数组,又同时修改这个数组里面的内容,导致崩溃,网上的方法如下:
NSMutableArray * arrayTemp = xxx;
NSArray * array = [NSArray arrayWithArray: arrayTemp];
for (NSDictionary * dic in array) {
if (condition){
[arrayTemp removeObject:dic];
}
}
这种方法就是在定义一个一模一样的数组,便利数组A然后操作数组B
NSMutableArray *tempArray = [[NSMutableArray alloc]initWithObjects:@"12",@"23",@"34",@"45",@"56", nil];
[tempArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:@"34"]) {
*stop = YES;
if (*stop == YES) {
[tempArray replaceObjectAtIndex:idx withObject:@"3333333"];
}
}
if (*stop) {
NSLog(@"array is %@",tempArray);
}
}];
找到符合的条件之后,暂停遍历,然后修改数组的内容
2.
error in __connection_block_invoke_2: Connection interrupted