NSFastEnumerationMutationHandler crash

六月ゝ 毕业季﹏ 提交于 2019-12-19 03:26:06

问题


Could anyone possibly help me here, why I am getting NSFastEnumerationMutationHandler crash all of a sudden in my code. I am all but blank why this crash poped up all of a sudden and how to squash this one.

Thanks.


回答1:


Crash Error: **** Terminating app due to uncaught exception 'NSGenericException', reason: '* **Collection <__NSArrayM: 0x610000859410> was mutated while being enumerated.'*

You must be trying to change an array while you using fast enumeration.

Example

for ( id anObject in anArray ) {
    if ( /* anObject satisfies some condition */ ) {
        [anArray removeObject:anObject];
    }
}

That shouldn't be done. Use a different array or probably filteredArrayUsingPredicate: method to filter. Remedy, however, depends on what you're trying to do.




回答2:


Came here looking for a solution and ended up taking a copy of the original array to get around the issue.

for (NSObject *object in [array copy]) {
    if(condition) {
        [array removeObject....]
        break;
    }
}


来源:https://stackoverflow.com/questions/6608173/nsfastenumerationmutationhandler-crash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!