Objective c 如何将3d不可变数组转换为可变数组?
似乎当我使用mutableCopy时,数组的第一个维度保持可变,但数组中的所有数组都变得不可变 我当前的代码似乎没有效果,尝试编辑数组会导致NSInvalidArgumentException 该代码应该对输入进行深度复制(一个3d数组),然后确保它是可变的Objective c 如何将3d不可变数组转换为可变数组?,objective-c,arrays,deep-copy,Objective C,Arrays,Deep Copy,似乎当我使用mutableCopy时,数组的第一个维度保持可变,但数组中的所有数组都变得不可变 我当前的代码似乎没有效果,尝试编辑数组会导致NSInvalidArgumentException 该代码应该对输入进行深度复制(一个3d数组),然后确保它是可变的 -(NSMutableArray*) copyMutable :(NSMutableArray*) input{ NSMutableArray* copyInput = [[input mutableCopy] autorelease];
-(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;
-(NSMutableArray*)copyMutable:(NSMutableArray*)输入{
NSMutableArray*copyInput=[[input mutableCopy]自动释放];
NSMUTABLEARRY*副本=
[[[NSMutableArray alloc]initWithArray:copyInput copyItems:YES]自动释放];
NSMUTABLEARRY*copylayer;
NSMUTABLEARRY*copylayertwo;
arraycount=0;
arraycountTwo=0;
arraycountThree=0;
NSMutableArray*inputCopy=[[NSMutableArray alloc]init]autorelease];
对于(inta=0;a对不起,我的不好…似乎我漏掉了一点代码。应该是
copylayertwo=[[copy objectAtIndex:arraycount]objectAtIndex:arraycountTwo]可变复制]自动删除
此外,我似乎为循环长度输入了错误的变量,并重置了计数器
我应该停止熬夜