当你对一个可变数组( NSMutabeArray)进行枚举的同时又去修改他的内容,比如搜索到某个符合的对象再删除它。就会引发这样的crash的信息:
Collection <__NSArrayM: 0x61000024df50> was mutated while being enumerated.
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSDate* date=[NSDate date];
NSMutableArray* myArray=[NSMutableArray arrayWithObjects:date,@"hello",nil];
NSLog(@"遍历前:%@",myArray);
// for (id item in myArray) //这样会引发crash
// {
// if ([item isEqualTo:date])
// {
// NSLog(@"当前的位置 %lu",(unsigned long)[myArray indexOfObject:item]);
// [myArray removeObject:item];//在遍历这个数组的时候,你又去删除它里面的元素,会引发这样的c