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. Python验证码识别处理实例

    一.准备工作与代码实例 1.PIL.pytesser.tesseract (1)安装PIL:下载地址:http://www.pythonware.com/products/pil/(CSDN下载) 下 ...

  2. 使用swig将C/C++代码转为JAVA接口(Windows平台)

    小弟一直没用过Linux. 平时的码也只是在WINDOW上用SWIG或CYGWIN进行编译. 下面的例子,先从网上找来一个.c文件. example.c /* File : example.c */ ...

  3. go语言基础之局部变量特点

    1.局部变量特点 示例1: package main import "fmt" func main() { //定义在{}里面的变量就是局部变量,只能在{}里面有效 //执行到定义 ...

  4. C#中载入界面的几种做法

    1. 采用事件委托的方法  对象:主窗体:FrmMain 加载窗体:FrmLoading  思路:  在主窗体加载前显示窗体FrmLoading,当主窗体加载完毕后(第一次显示的时候),关闭FrmLo ...

  5. 十个书写Node.js REST API的最佳实践(上)

    收录待用,修改转载已取得腾讯云授权 原文:10 Best Practices for Writing Node.js REST APIs 我们会通过本文介绍下书写Node.js REST API的最佳 ...

  6. android学习的网站收集

    1. http://mob.com/#/index 提供分享等统一解决方案 2. http://bbs.apkbus.com/explore/ 这个类似的quroa问答模块,覆盖不错.就是人气,稍差. ...

  7. (1)风色从零单排《C++ Primer》 一个简单的c++程序

    从零单排<C++ Primer> --(1)一个简单的c++程序 本次学习收获 0.写在前面 风色以前上过C++的课程,然而当时并没有认真去学,基本不能使用c++来作项目开发. 这次又一次 ...

  8. 如何判断linux用户是否为root用户

    看命令行提示符 ,如果是#,那就是root用户,如下图:[root@localhost /]# 如果是$,那就是普通用户,如下图:[test@localhost ~]$

  9. SpringMVC请求参数和响应结果全局加密和解密

    前提 前段时间在做一个对外的网关项目,涉及到加密和解密模块,这里详细分析解决方案和适用的场景.为了模拟真实的交互场景,先定制一下整个交互流程.第三方传输(包括请求和响应)数据报文包括三个部分: 1.t ...

  10. MySQL 5.1参数

    MySQL 5.1.73参数 Variable_name    Valueauto_increment_increment 1auto_increment_offset 1autocommit ONa ...