崩溃与“集合......被枚举时变异”

时间:2013-02-06 00:20:11

标签: ios ios5

崩溃后我收到了这个错误:

malloc: *** error for object 0x75617b4: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
2013-02-05 19:15:44.950 BusinessIdea[3171:15e03] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSSetM: 0x72dc5c0> was mutated while being enumerated.'

我不熟悉这个错误。知道它可能是什么吗?

1 个答案:

答案 0 :(得分:10)

整个'枚举时修改'错误意味着您可能在迭代它时尝试从集合中删除某些内容。例如

for(NSString *str in array){
     if([str isequalToString:@"delete me"]){
         [array removeObject:str];   //this will cause a problem,
     }
}   

相反,如果要使用快速枚举循环,则需要维护要删除的项目列表,然后在迭代步骤后删除它们。如果你想删除项目,替代方法是使用传统的索引循环。