解决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.这个错误,查了半天才发 ...
随机推荐
- deal with 'non-admin area' warn
We usually use the follow code to delete product in Magento $product = Mage::getSingleton('catalog/p ...
- Android SoundPool 的使用以及原理分析
好吧,我们今天来聊聊SoundPool这东西. 据说这个东西是冰激凌(Android4.0)里才引入的一个新东西.按照官方的意思大多数情况下是给游戏开发用的,比如一个游戏10关,它能在游戏开始前一次加 ...
- kobox: key_proc.c -v1 怎样使用proc文件系统调试驱动
使用proc文件系统能够非常方便调试驱动.查看驱动中的一些数据 平台:TQ2440 系统版本号: root@ubuntu:/mnt/shared/kobox# uname -a Linux ubunt ...
- 做ie8css样式时浏览器默认杂项模式遇到的一个小坑
1 进行ie浏览器的样式兼容的时候,首先要确保打开浏览器浏览网页的时候的文本模式要为当前浏览器的"标准模式",注意<!DOCTYPE html>不缺失不错误,以免浏览器 ...
- android的Home键的监听封装工具类(一)
android的Home键的监听封装: package com.gzcivil.utils; import android.content.BroadcastReceiver; import andr ...
- Linux 07 故障恢复
1. 模拟MBR扇区被破坏后的修复. MBR故障恢复: 1.备份 添加硬盘 启动操作系统: 添加硬盘: 对分区格式化: 挂载: 做备份: 破坏MBR 重启系统: 关闭虚拟机 设置光盘启动 救援模式: ...
- Unity截图
什么都不说了,直接上代码. using UnityEngine; using System.Collections; using System.IO; public class CutImage : ...
- 关于中文乱码的解决方法(URL方式)
假设keyWord ='阳光'; url="play.jsp? keyWord ="+ keyWord 若按照上述的地址直接访问,则中文会变成乱码.必须使用encodeURI()进 ...
- NOIP第二次模拟赛 stage1【划分数列(seq.pas/c/cpp)
7划分数列(seq.pas/c/cpp) [题目描述] 给你一个有n个元素的数列,要求把它划分成k段,使每段元素和的最大值最小 [输入格式] 第一行两个正整数n,k 第二行为此数列ai [输出格式] ...
- php 接收curl json 数据
curl -H "Content-Type: application/json" http://127.0.0.1:8000 -X POST -d 'xxxx' php $strP ...