When the program appears this prompt, because you side of the convenience of the array, but also modify the contents of the array, resulting in a crash, the online method is as follows:
| 123456789 |
nsmutablearray * arraytemp = xxx; nsarray * array = [ nsarray arraywitharray: arraytemp] ; for ( Nsdictionary * dic in array) {     if (condition) {        [arraytemp removeobject:dic];     } } |
This method is to define an identical array, to facilitate array A and then manipulate array B
Today we finally found a faster way to delete the contents of the array and modify the contents of the array:
| 1234567891011121314151617181920212223 |
NSMutableArray*tempArray = [[NSMutableArrayalloc]initWithObjects:@"12",@"23",@"34",@"45",@"56", nil];[tempArray enumerateObjectsUsingBlock:^(idobj, NSUIntegeridx, BOOL*stop) {if([obj isEqualToString:@"34"]) {*stop = YES;if(*stop == YES) {[tempArray replaceObjectAtIndex:idx withObject:@"3333333"];}}if(*stop) {NSLog(@"array is %@",tempArray);}}]; |
Using block to operate, according to the information, found block convenience than for convenience of about 20% faster, this principle is this:
After a qualifying condition is found, the traversal is paused and the contents of the array are modified
This method is very simple.
Fix collection <__NSArrayM:0xb550c30> was mutated while being enumerated