字典
當(dāng)程序出現(xiàn)這個提示的時候, 是因為你一邊便利字典,又同時修改這個數(shù)組里面的內(nèi)容,導(dǎo)致崩潰,解決方法如下:
for (NSString *key in [tempdic allKeys]) {
NSString *value = [tempdic objectForKey:key];
[tempdic setValue:value forKey:key];
}
數(shù)組
當(dāng)程序出現(xiàn)這個提示的時候,是因為你一邊便利數(shù)組,又同時修改這個數(shù)組里面的內(nèi)容,導(dǎo)致崩潰,網(wǎng)上的方法如下:
NSMutableArray * arrayTemp = xxx;
NSArray * array = [NSArray arrayWithArray: arrayTemp];
for (NSDictionary * dic in array) {
if (condition){
[arrayTemp removeObject:dic];
}
}
這種方法就是在定義一個一模一樣的數(shù)組,便利數(shù)組A然后操作數(shù)組B
今天終于找到了一個更快接的刪除數(shù)組里面的內(nèi)容以及修改數(shù)組里面的內(nèi)容的方法:
NSMutableArray *tempArray = [[NSMutableArray alloc]initWithObjects:@"12",@"23",@"34",@"45",@"56", nil];
[tempArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:@"34"]) {
*stop = YES;
if (*stop == YES) {
[tempArray replaceObjectAtIndex:idx withObject:@"3333333"];
}
}
if (*stop) {
NSLog(@"array is %@",tempArray);
}
}];