<__NSArrayM:XXXXXX> was mutated while being enumerated.

這樣的代碼運(yùn)行起來會(huì)出現(xiàn)崩潰

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

在對可變數(shù)據(jù)類型如字典、數(shù)組,進(jìn)行快速遍歷的時(shí)候,是不可以對其增、刪操作。否則就會(huì)引起“<__NSArrayM:XXXXXX> was mutated while being enumerated.”的崩潰。

官網(wǎng)對快速排序的說明(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)
)。重點(diǎn)為NOTE的內(nèi)容:

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;
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,889評論 2 45
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    wgl0419閱讀 6,598評論 1 9
  • 我看驢得水看哭了。 看完影片百度了一下一曼的扮演者任素汐。 這是一個(gè)并不漂亮的演員,但卻能在一顰一笑間勾人魂魄。她...
    小飛俠303閱讀 600評論 2 3
  • 雷鋒塔 高而嚴(yán) 無情又無義 壓了多少年 壓不往 我 無邊的 情緒 日亦思 夜亦念 請小精靈 快快 送去 我的意念
    蘭情二月天閱讀 413評論 5 11
  • 扁豆是一種豆類植物,是人們餐桌上的一種蔬菜。 摘下新鮮的扁豆,把外層的筋撕去。 扁豆炒土豆,味道不錯(cuò)。 扁豆不僅可...
    吳建平閱讀 333評論 0 0

友情鏈接更多精彩內(nèi)容