'*** Collection <__NSArrayM: 0x60000025cad0> was mutated while being enumerated.'

当程序出现这个提示时候:'*** Collection <__NSArrayM: 0x60000025cad0> was mutated while being enumerated.'

NSMutableArray *arr = [[NSMutableArray alloc]initWithCapacity:10];
    for (int i = 0; i< 10; i++) {
        [arr addObject:[NSNumber numberWithInt:i]];
        
    }
    for (NSNumber *num in arr) {
        [arr removeObject:num];
    }

【原因】 是因为一边遍历数组,又同时修改这个数组里面的内容,导致崩溃。

用作笔记

你可能感兴趣的:('*** Collection <__NSArrayM: 0x60000025cad0> was mutated while being enumerated.')