应用程序崩溃异常:***集合在枚举时发生了变异

时间:2016-01-25 03:51:28

标签: ios crash

应用程序崩溃异常:

 *** Collection  was mutated while being enumerated.
2016-01-25 08:55:30.606 Mink Chatter[416:70120] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection  was mutated while being enumerated.'
*** First throw call stack:
(0x1821c5900 0x181833f80 0x1821c5334 0x186ead9f0 0x186ead7d8 0x186ead6d8 0x1001a6834 0x10015ddc0 0x100905bf0 0x100905bb0 0x100914e10 0x1009144d8 0x181e2d470 0x181e2d020)
libc++abi.dylib: terminating with uncaught exception of type NSException

代码:

_totalcount

1 个答案:

答案 0 :(得分:0)

当您枚举某个对象(例如,NSMutableArray或NSMutableSet)时,使用for循环(for(对象中的id _obj))并在该循环中删除或向同一对象添加一些对象时,会出现问题。这是不可能的,并导致异常。

试试这个: 将代码保持在下面的循环中。

@synchronized(self)
  {
       // your code goes here 
  }

希望这有帮助。