bug:

今天做项目的时候遇到了这样一个崩溃信息:

解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-

 

2017-06-22 16:45:42.229 ViewTest[2638:c07] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.'

当程序出现这个提示的时候,是因为你一边便利数组,又同时修改这个数组里面的内容,导致崩溃,网上的方法如下:

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);

}

}];

利用block来操作,根据查阅资料,发现block便利比for便利快20%左右,

这个的原理是这样的:

找到符合的条件之后,暂停遍历,然后修改数组的内容

这种方法非常简单哟

解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-的更多相关文章

  1. iOS之解决崩溃Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.

    崩溃提示:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CAL ...

  2. 解决Collection <__NSArrayM: 0x7f8168f7a750> was mutated while being enumerated.'

    当程序出现这个提示的时候,是因为你一边便利数组,又同时修改这个数组里面的内容,导致崩溃,网上的方法如下: NSMutableArray * arrayTemp = xxx; NSArray * arr ...

  3. *** Collection <__NSArrayM: 0x600000647380> was mutated while being enumerated.

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

  4. bug:*** Collection <__NSArrayM: 0x1c444d440> was mutated while being enumerated.

    崩溃提示:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CAL ...

  5. reason: '*** Collection <__NSCFArray: 0x7ffa43528f70> was mutated while being enumerated.'

    一,错误分析 1.崩溃代码如下: //遍历当前数组,判断是否有相同的元素 for (NSString *str in self.searchHistoryArrM) { if ([str isEqua ...

  6. 【转】was mutated while being enumerated 你是不是以为你真的懂For...in... ??

    原文网址:http://www.jianshu.com/p/ad80d9443a92 支持原创,如需转载, 请注明出处你是不是以为你真的懂For...in... ??哈哈哈哈, 我也碰到了这个报错 . ...

  7. 异常Crash之 NSGenericException,NSArray was mutated while being enumerated

    *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NS ...

  8. Objective-C Collection was mutated while being enumerated crash

    Collection was mutated while being enumerated

  9. 解决Collection was modified; enumeration operation may not execute异常

    今天在使用foreach循环遍历list集合时,出现Collection was modified; enumeration operation may not execute.这个错误,查了半天才发 ...

随机推荐

  1. luigi框架--关于python运行spark程序

    首先,目标是写个python脚本,跑spark程序来统计hdfs中的一些数据.参考了别人的代码,故用了luigi框架. 至于luigi的原理 底层的一些东西Google就好.本文主要就是聚焦快速使用, ...

  2. JVisualVM简介与内存泄漏实战分析

    JVisualVM简介与内存泄漏实战分析 学习了:https://blog.csdn.net/kl28978113/article/details/53817827

  3. 【论文笔记】Leveraging Datasets with Varying Annotations for Face Alignment via Deep Regression Network

    參考文献: Zhang J, Kan M, Shan S, et al. Leveraging Datasets With Varying Annotations for Face Alignment ...

  4. [OpenGL红宝书]第一章 OpenGL概述

    第一章 OpenGL概述 标签(空格分隔): OpenGL 第一章 OpenGL概述 1 什么是OpenGL 2 初识OpenGL程序 3 OpenGL语法 4 OpenGL渲染管线 41 准备向Op ...

  5. SQL语法 之 表连接

    一.连接条件 连接查询中用来连接连个表的条件称为连接条件或连接谓词.其形式为: [<表1>].<列名1> <连接运算符> [<表2>].<列2&g ...

  6. java使用链栈实现数制转换

    java实现链栈在前面有所介绍:http://www.cnblogs.com/lixiaolun/p/4644141.html 将前面java实现链栈的代码稍作修改: package linkedst ...

  7. linux安装卸载软件

    转自:http://www.cnblogs.com/propheteia/archive/2012/06/26/2563383.html configure作用:是源码安装软件时配置环境用的 他根据你 ...

  8. 使用ASP.NET上传多个文件到服务器

    在Email系统中经常会上传多个文件到服务器,用户大多习惯一次上传所有的文件,而不是逐个上传,我们可以使用javascript动态地添加file元素到表单,然后在服务器端处理这些file 效果图如下: ...

  9. 虚拟机chrome os 没有可用网络错误

    从http://chromeos.hexxeh.net/ 下载了一个chrome os的VM版本的,在VM9上打开运行,一直提示没有可用网络 解决方案 查看虚拟机的网络设置设置为 NAT方式 查看主机 ...

  10. git config 的全局配置

    使用git的全局配置   .gitconfig 一:修改 用户下的.gitconfig 修改如图信息,添加你的信息 二: 命令添加 $ git config --global user.name   ...