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. Android 4.4 KitKat升级率已经接近18%(2014-07-09 07:29)

    腾讯数码讯(编 译:张秀梅)按照惯例, 每个月的第一个星期的星期一谷歌都会发布最新一期Android版本分布图.从去年十月末谷歌发布Android 4.4 KitKat以来,截止到目前为止Androi ...

  2. DEDECMS网站管理系统Get Shell漏洞

    漏洞版本: DEDECMS 5.3/5.6 漏洞描述: DedeCms 基于PHP+MySQL的技术开发,支持Windows.Linux.Unix等多种服务器平台,从2004年开始发布第一个版本开始, ...

  3. Orchard运用 - 整合Disqus评论插件

    评论对于博客系统那是必须具备的一个功能,Orchard本身也默认实现了评论模块,你可以集成到其他内容,比如博客随笔,不过觉得有点寒碜,样式有点呆板.幸运的是,你可以简单集成第三方评论插件,比如Disq ...

  4. powerVR tbdr 硬件架构理解

    有两点 TSP里的iteration 和那个vertex data 到 tsp的 *2 itedration是为了把 ps里面uv的动态改变提前算出来给 texture fetch用 这个的通用方法是 ...

  5. Android -- Android JUint 与 Sqlite

    创建一个数据库                                                                           public PersonSQLit ...

  6. Thinkphp学习笔记6-redirect 页面重定向

    ThinkPHP redirect 方法可以实现页面的重定向(跳转)功能.redirect 方法语法如下: $this->redirect(string url, array params, i ...

  7. Android之GPS定位详解

    一.LocationManager LocationMangager,位置管理器.要想操作定位相关设备,必须先定义个LocationManager.我们可以通过如下代码创建LocationManger ...

  8. ajax交互Struts2的action(1)

    1.客户端网页代码 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://w ...

  9. 算法笔记_148:有向图欧拉回路求解(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Description A catenym is a pair of words separated by a period such that t ...

  10. vue 表单 验证 async-validator

    1.使用插件async-validator async-validator 地址:https://github.com/yiminghe/async-validator 2.示例(vue+elemen ...