解决Collection <__NSArrayM: 0x7f8168f7a750> 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: 0x7f8168f7a750> was mutated while being enumerated.'的更多相关文章
- 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
bug: 今天做项目的时候遇到了这样一个崩溃信息: 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumera ...
- iOS之解决崩溃Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.
崩溃提示:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CAL ...
- *** 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.这个错误,查了半天才发 ...
随机推荐
- Backward Digit Sums(暴力)
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5664 Accepted: 32 ...
- How to set custom JsonSerializerSettings for Json.NET in MVC 4 Web API?
ou can customize the JsonSerializerSettings by using theFormatters.JsonFormatter.SerializerSettings ...
- MAC COCOA call command 调用终端控制台程序
MAC COCOA call command 调用终端控制台程序 STEP 1 先写一个C++ DOS程序 STEP2 使用NSTask来运行,然后用NSPipe和 NSData来接受运行的结果字符串 ...
- jQuery源码笔记——准备
将变量局部化 作为一个库首要解决的问题就是防止影响全局的变量.自执行匿名函数可以很好的实现这一点. 传入window,undefiend是将全局变量改为局部变量,根据作用域链访问原理,访问更快一些,. ...
- bootstrap-js(4)标签页
实例 标签页(Tab)在 Bootstrap 导航元素 一章中介绍过.通过结合一些 data 属性,您可以轻松地创建一个标签页界面. 通过这个插件您可以把内容放置在标签页或者是胶囊式标签页甚至是下拉菜 ...
- Gulp思维——Gulp高级技巧
本文翻译自Getting gulpy -- Advanced tips for using gulp.js 感受过gulp.js带来的兴奋过后,你需要的不仅仅是它的光鲜,而是切切实实的实例.这篇文章讨 ...
- Fedora、CentOS install TTF/otf fonts
Step 1:切换至字体下载目录: [Richard@localhost Downloads]$ ll | grep otf -rw-rw-r--. Richard Richard 7月 RBNo2L ...
- 解压tomcat后一闪而过的问题
解压tomcat压缩包后,直接点击startup会出现一闪而过. 免安装的tomcat双击startup.bat后,启动窗口一闪而过,而且tomcat服务未启动. 原因是:在启动tomcat是,需要读 ...
- OC语法9——Category类别
Category(分类): 当我们在开发过程中要给类添加新的方法时,一般不要去动原类. 再不改动原类的限制下,怎么拓展类的方法?以往我们的做法是新建子类使其继承该类,然后通过子类拓展类的行为. OC提 ...
- Php5.3的lambda函数以及closure(闭包)
从php5.3以后,php也可以使用lambda function(可能你会觉得是匿名函数,的确是但不仅仅是)来写类似javascript风格的代码: $myFunc = function() { e ...