我搜索过这个问题,我知道这是因为在枚举数组时操作了数组。在我的代码的前面,我使用的是:
-(BOOL)busy
{
for(DataRequest* request in self.active)
if(!request.invisible)
return YES;
return NO;
}
和 -(BOOL)busy
在从服务器加载数据时被非常频繁地调用。同样在我的代码中,我有一些行在 self.active
中添加和删除对象。正因为如此,我得到了异常(exception)。然后我将代码更改为:
-(BOOL)busy
{
self.tempActive = self.active;
for(DataRequest* request in _tempActive)
if(!request.invisible)
return YES;
return NO;
}
但我仍然遇到同样的异常。我做错了什么,有什么想法吗?这是唯一使用 self.tempActive
的代码。
我得到的异常是:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x9ec8f60> was mutated while being enumerated.'
最佳答案
您需要了解类和堆栈对象(如整数和事物)之间的区别。如果它是一个类,则将某些东西设置为等于其他东西不会创建它的副本。您需要改用 [self.active copy]
。
关于ios - 一般异常 : Collection was mutated while being enumerated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21330123/