【问题标题】:Crash with "Collection ... mutated while being enumerated"与“集合......在枚举时发生突变”崩溃
【发布时间】:2013-01-21 01:59:48
【问题描述】:

崩溃后出现此错误:

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.'

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

【问题讨论】:

    标签: ios ios5


    【解决方案1】:

    整个 'modified while being enumerated' 错误意味着您可能在迭代集合时尝试从集合中删除某些内容。例如

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

    如果要使用快速枚举循环,则需要构建要删除的项目列表,然后在迭代步骤后将其删除。如果要删除循环主体中的项目,替代方法是使用传统的索引 for 循环。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 2012-07-30
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多