Collection NSArrayM was mutated while being enumerated
来源:互联网 发布:网络实体小说排行榜 编辑:程序博客网 时间:2024/05/18 01:40
NSMutableArray* arrMutable = [NSMutableArray array];
//不能在枚举可变数组的同时增删其项目,下面的写法会报错。
for(AClass* item in arrMutable){
BOOL needRemove = YES;
if(needRemove){
[arrMutable removeObject:item];
}
}
正确作法:
NSMutableArray* arrMutable = [NSMutableArray array];
//不能对mutable arr在枚举的同时增删项目,下面的作法会报错。
for(AClass* item in [arrMutable copy]){
BOOL needRemove = YES;
if(needRemove){
[arrMutable removeObject:item];
}
//不能在枚举可变数组的同时增删其项目,下面的写法会报错。
for(AClass* item in arrMutable){
BOOL needRemove = YES;
if(needRemove){
[arrMutable removeObject:item];
}
}
正确作法:
NSMutableArray* arrMutable = [NSMutableArray array];
//不能对mutable arr在枚举的同时增删项目,下面的作法会报错。
for(AClass* item in [arrMutable copy]){
BOOL needRemove = YES;
if(needRemove){
[arrMutable removeObject:item];
}
}
注意,如果是自定义类,如果在数组中比较是否相等,需要重写自定义类的isEqual和hash这两个方法:
#pragma mark - override NSObject 数组中比较时需要 -
- (BOOL)isEqual:(id)other
{
if ([otherisKindOfClass: [AClassclass]]
&& [((AClass*)other).name isEqualToString:self.name]){
returnYES;
}else{
returnNO;
}
}
- (NSUInteger)hash
{
return [_name hash];
}
0 0
- Collection NSArrayM was mutated while being enumerated
- was mutated while being enumerated.
- was mutated while being enumerated
- was mutated while being enumerated.
- was mutated while being enumerated
- 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
- 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
- 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
- Collection <__NSArrayM: 0xxxxxxx> was mutated while being enumerated.
- Collection <__NSArrayM: 0xxxxxxx> was mutated while being enumerated.
- Collection <__NSCFDictionary: 0xc425570> was mutated while being enumerated.
- reason: ‘*** Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated
- *** Collection <__NSArrayM: 0x7f9fb3c48bc0> was mutated while being enumerated问题
- *** Collection <__NSArrayM: 0x7fda017e0f40> was mutated while being enumerated.'
- 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
- Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
- Collection <__NSArrayM: 0x> was mutated while being enumerated.
- iOS:编译错误 NSArrayM: 0x7fdbe0c70600> was mutated while being enumerated
- 学习Qt的资源-网站、论坛、博客等(必看)
- Hadoop应用——Map端Join操作
- 软件的版本标志
- linux 发送邮件
- JAVA设计模式(10):结构型-组合模式(Composite)
- Collection NSArrayM was mutated while being enumerated
- Nginx linux服务搭建
- 反转链表
- activiti简介
- 51nod 1118 机器人走方格(简单DP)
- POJ 3070 Fibonacci(矩阵快速幂)
- AR与VR初探
- c语言文件操作总结
- java中关于小数的四舍五入问题