错误提示:
Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘*** Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.’
原因:由于遍历数组时候 修改了数组中的数据 导致错误。
解决办法:
定义一个数组B,并把要遍历的数组A的值赋给他 。
然后遍历数组B 要修改数据的A就可以修改数据了。
NSArray *arr = content[@"workface"];
for (NSDictionary *dictin arr) {
if ([dict[@"workfaceid"]isEqual:_faceInfo[@"workfaceid"]]) {
// 先移除后添加
[content[@"workface"]removeObject:dict];
[content[@"workface"]addObject:_faceInfo];
}
}
另一种快捷 的方法是
[self.viceMoresels enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isEqualToString:[@(sender.tag-10001) stringValue]]) {
*stop = YES;
if (*stop==YES) {
[self.viceMoresels removeObjectAtIndex:idx];
}
}
}];
这种方法 遍历速度更快 。本文发布于:2024-01-29 18:56:09,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170652577317560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |