写了一段这样的代码:
for (ShopCartModel *model in weakSelf.dataArray) {
for (NSString *id_ in ids) {
if ([[NSString stringWithFormat:@"%@",model.id_] isEqualToString:[NSString stringWithFormat:@"%@",id_]]) {
[weakSelf.dataArray removeObject:model];
}
}
}
抛出异常: was mutated while being enumerated.'
解决方法(对数组进行备份):
NSArray *array = [NSArray arrayWithArray:weakSelf.dataArray];
for (ShopCartModel *model in array) {
for (NSString *id_ in ids) {
if ([[NSString stringWithFormat:@"%@",model.id_] isEqualToString:[NSString stringWithFormat:@"%@",id_]]) {
[weakSelf.dataArray removeObject:model];
}
}
}