objc-crash收集與分析

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章