美文网首页
<__NSArrayM: 0x17425f440> was m

<__NSArrayM: 0x17425f440> was m

作者: 隔壁老鹿 | 来源:发表于2017-10-09 18:13 被阅读0次

这类错是因为:

当程序出现这个提示的时候,是因为你一边便利数组,又同时修改这个数组里面的内容,导致崩溃。此时我们可以采用block遍历里的stop解决。通过满足条件后,暂停循环再删除数组里的元素:

错误代码:

for (UISwitch * tempswitch in self.switchArr) {

  if (tempswitch.tag == switchFunc.tag) {

  [self.switchArr removeObject:tempswitch];

 }

}

用block遍历后的代码:

[self.switchArrenumerateObjectsUsingBlock:^(id_Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop) {

UISwitch* tempswitch = obj;

if(tempswitch.tag== switchFunc.tag) {

*stop =YES;

if(*stop ==YES) {

[self.switchArrremoveObject:tempswitch];

}

}

}];

相关文章

网友评论

      本文标题: <__NSArrayM: 0x17425f440> was m

      本文链接:https://www.haomeiwen.com/subject/jovpyxtx.html