似乎当我使用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;
}
答案 0 :(得分:0)
抱歉,我的不好......似乎我错过了一些代码。它应该是 copylayertwo = [[[copy objectAtIndex:arraycount] objectAtIndex:arraycountTwo] mutableCopy] autorelease;
此外,似乎我为循环长度输入了错误的变量并重置了计数器。
我应该停止熬夜...