Collection <__NSArrayM: 0x10e8e49f0> was mutated while being enumerated.

遍历的时候对数组的删除操作,会导致程序crash。原因是因为不允许一边修改数组的内容,一边进行遍历。
解决的方法有两种:
一: 改用for (int i = 0; i< dataSource.count;i++){ }
二:将数组深拷贝,如:

    NSMutableArray *array = self.userInfoArray.mutableCopy;
            for (HNLianMaiUserInfoModel *model in array) {
                if (currentTime-[model.time integerValue]>= time) {
                    [self.userInfoArray removeObject:model];
                    [_listView refreshList:self.userInfoArray]; //刷新
                        [self refreshRequestButton];
                }

mutableCopy对self.userInfoArray进行了深拷贝,所以 array 与 self.userInfoArray 不是同一个地址,使用array进行遍历时操作self.userInfoArray,不会导致闪退。

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