Init a nsarray nsmutablearray *arr2 = [Nsmutablearray array]; for (int i=0; i<10; ++i) {nsmutabledictionary *d = [Nsmutabledictionary dictionarywithobjectsandkeys:[nsstr ing stringwithformat:@ "%d", I], @ "A", nil]; [Arr2 Addobject:d]; }//wrong for (Nsmutabledictionary *s in arr2) {if ([s[@ "a"] isequaltostring:@ "3"]) { [Arr2 removeobject:s]; While this is safe for s[@ "a"] = @ "Eeee"; }}//safe 1. [Arr2 enumerateobjectsusingblock:^ (nsmutabledictionary *obj, Nsuinteger idx, BOOL *stop) {if ([obj[@ "a"] isequaltostring:@ "3"]) {*stop = YES; [Arr2 Removeobject:obj]; or obj[@ "a"] = @ "4ewewewe"; } }]; Safe 2. Nsarray *tmp = [Nsarray arraywitharray:arr2]; For (Nsmutabledictionary *s in tmp) {if ([s[@ "a"] isequaltostring:@ "3"]) { S[@ "a"] = @ "Eeee"; [Arr2 removeobject:s]; } }
PS: Search for a supplementary word
the convenience content in the//forin cycle cannot be changed, because if there are fewer things to change its convenience, and the system will not allow this to happen, it will crash ... However, when the last content is changed, it is not crash, because the traversal is over and the content is modified after the end is allowed .
Bug-ios:collection <__NSArrayM:0x> was mutated while being enumerated.