似乎当我使用 mutableCopy 时,数组的第一个维度保持可变,但数组中的所有数组都变得不可变。
我当前的代码似乎没有效果,并且尝试编辑数组会导致 NSInvalidArgumentException。
该代码应该对输入(3d 数组)进行深层复制,然后确保它是可变的。
-(NSMutableArray*) copyMutable :(NSMutableArray*) input{
NSMutableArray* copyInput = [[input mutableCopy] autorelease];
NSMutableArray* copy =
[[[NSMutableArray alloc] initWithArray:copyInput copyItems:YES] autorelease];
NSMutableArray* copylayer;
NSMutableArray* copylayertwo;
arraycount=0;
arraycountTwo=0;
arraycountThree=0;
NSMutableArray* inputCopy = [[[NSMutableArray alloc] init]autorelease];
for (int a=0; a<[inputCopy count]; a++){
copylayer=[[[copy objectAtIndex:arraycount] mutableCopy]autorelease];
[copy replaceObjectAtIndex:arraycount withObject:copylayer];
for (int b=0; b<[inputCopy count]; b++){
copylayertwo = [[copy objectAtIndex:arraycount] objectAtIndex:arraycountTwo];
[[copy objectAtIndex:arraycount] replaceObjectAtIndex:arraycountTwo withObject:copylayertwo];
arraycountTwo++;
}
arraycount++;
}
return copy;
}