<__NSArrayM:XXXXXX> was mutated while being enumerated.

这样的代码运行起来会出现崩溃

//targetButton
for (UIButton * button in self.selectedBtnArr)
 {
    if (targetButton.tag ==  button.tag)
   {
        [self.selectedBtnArr removeObject:button];
    }
}

在对可变数据类型如字典、数组,进行快速遍历的时候,是不可以对其增、删操作。否则就会引起“<__NSArrayM:XXXXXX> was mutated while being enumerated.”的崩溃。

官网对快速排序的说明(https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSEnumerator_Class/index.html](https://link.jianshu.com?t=https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSEnumerator_Class/index.html)
)。重点为NOTE的内容:

It is not safe to modify a mutable collection while enumerating through it. Some enumerators may currently allow enumeration of a collection that is modified, but this behavior is not guaranteed to be supported in the future.

解决方案:

//targetButton
for (UIButton * button in self.selectedBtnArr)
 {
    if (targetButton.tag ==  button.tag)
   {
        [self.selectedBtnArr removeObject:button];
        break;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,556评论 2 45
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    wgl0419阅读 6,354评论 1 9
  • 我看驴得水看哭了。 看完影片百度了一下一曼的扮演者任素汐。 这是一个并不漂亮的演员,但却能在一颦一笑间勾人魂魄。她...
    小飞侠303阅读 519评论 2 3
  • 雷锋塔 高而严 无情又无义 压了多少年 压不往 我 无边的 情绪 日亦思 夜亦念 请小精灵 快快 送去 我的意念
    兰情二月天阅读 377评论 5 11
  • 扁豆是一种豆类植物,是人们餐桌上的一种蔬菜。 摘下新鲜的扁豆,把外层的筋撕去。 扁豆炒土豆,味道不错。 扁豆不仅可...
    吴建平阅读 293评论 0 0