解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
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.-的更多相关文章
- iOS之解决崩溃Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.
崩溃提示:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CAL ...
- 解决Collection <__NSArrayM: 0x7f8168f7a750> was mutated while being enumerated.'
当程序出现这个提示的时候,是因为你一边便利数组,又同时修改这个数组里面的内容,导致崩溃,网上的方法如下: NSMutableArray * arrayTemp = xxx; NSArray * arr ...
- *** Collection <__NSArrayM: 0x600000647380> was mutated while being enumerated.
*** Collection <__NSArrayM: 0x600000647380> was mutated while being enumerated.
- bug:*** Collection <__NSArrayM: 0x1c444d440> was mutated while being enumerated.
崩溃提示:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CAL ...
- reason: '*** Collection <__NSCFArray: 0x7ffa43528f70> was mutated while being enumerated.'
一,错误分析 1.崩溃代码如下: //遍历当前数组,判断是否有相同的元素 for (NSString *str in self.searchHistoryArrM) { if ([str isEqua ...
- 【转】was mutated while being enumerated 你是不是以为你真的懂For...in... ??
原文网址:http://www.jianshu.com/p/ad80d9443a92 支持原创,如需转载, 请注明出处你是不是以为你真的懂For...in... ??哈哈哈哈, 我也碰到了这个报错 . ...
- 异常Crash之 NSGenericException,NSArray was mutated while being enumerated
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NS ...
- Objective-C Collection was mutated while being enumerated crash
Collection was mutated while being enumerated
- 解决Collection was modified; enumeration operation may not execute异常
今天在使用foreach循环遍历list集合时,出现Collection was modified; enumeration operation may not execute.这个错误,查了半天才发 ...
随机推荐
- 比較不错的一个ios找茬游戏源代码
找茬游戏源代码 .这个是一款很不错的ios找茬游戏源代码,该游戏的兼容性很好的.并且还能够支持ipad和iphone.UI界面设计得也很美丽,游戏源代码真的是一款很完美.并且又很完整的一款休闲类的游戏 ...
- DICOM:DICOM三大开源库对比分析之“数据加载”
背景: 上一篇博文DICOM:DICOM万能编辑工具之Sante DICOM Editor介绍了DICOM万能编辑工具,在日常使用过程中发现,“只要Sante DICOM Editor打不开的数据,基 ...
- 【转载】Redis在新浪微博中的应用
转载自文章 http://blog.me115.com/2013/12/19/redis-e5-9c-a8-e6-96-b0-e6-b5-aa-e5-be-ae-e5-8d-9a-e4-b8-ad-e ...
- Python开发之AJAX全套
概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用 一个简单操作需要 ...
- 【帧动画总结】AnimationDrawable Frame
Drawable Animation 开发者文档 位置:/sdk/docs/guide/topics/graphics/drawable-animation.html Drawable animati ...
- Android -- Service的开启关闭与生命周期
Service是Android 系统中的四大组件之一,是在一段不定的时间运行在后台,不和用户交互应用组件. service可以在很多场合的应用中使用,比如播放多媒体的时候用户启动了其他Activity ...
- SqlInXml 动态配置化
XML 描述方式. 整合Ognl+IBatis 根据Map型的输入参数, 动态组装Sql语句. 使用sqlRoot的 source="mysql01" 配置, 将自动读取mysql ...
- url: (6) Couldn’t resolve host ‘www.ttlsa.com’
http://www.ttlsa.com/linux/curl-6-couldnt-resolve-host/ 2. 解决问题 尝试解决方法: 修改dns # cat /etc/resolv.conf ...
- HDU 1565 1569 方格取数(最大点权独立集)
HDU 1565 1569 方格取数(最大点权独立集) 题目链接 题意:中文题 思路:最大点权独立集 = 总权值 - 最小割 = 总权值 - 最大流 那么原图周围不能连边,那么就能够分成黑白棋盘.源点 ...
- Android异步下载
概述 实现App常见下载公共 支持通知栏显示 支持 暂停.取消功能,使用Service.AsyncTask实现异步下载.特点简单.实用.方便源码扩展修改 详细 代码下载:http://www.demo ...