[英]How can I convert a 3d immutable array into a mutable array?
似乎當我使用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;
}
抱歉,我的問題...看來我錯過了一些代碼。 它應該是copylayertwo = [[[[復制objectAtIndex:arraycount] objectAtIndex:arraycountTwo] mutableCopy]自動釋放;
而且似乎我為循環長度輸入了錯誤的變量並重置了計數器。
我不應該熬夜...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.