能否請你幫我解決了以下錯誤:NSInternalInconsistencyException原因:「 - [__ NSCFArray replaceObjectAtIndex:withObject:]:變異的方法發送到不可變對象」
終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,究其原因: ' - [__ NSCFArray replaceObjectAtIndex:withObject:]:突變方法發送到不可變對象'
array_Info = [[NSMutableArray alloc] init];
array_Info = [dict_Temp objectForKey:@"Children"];
NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:self.array_Info];
int ran, arrayIndexing = 0;
while ([temp count] != 0)
{
ran = arc4random();
if(ran < 0)
ran*=-1;
ran = ran % [temp count];
if([temp count] == 1)
ran = 0;
NSLog(@"%d %d",arrayIndexing,ran);
[self.array_Info replaceObjectAtIndex:arrayIndexing withObject:[temp objectAtIndex:ran]];
[temp removeObjectAtIndex:ran];
arrayIndexing++;
}
不,我已經在代碼的第一行中聲明它是可變陣列。 –
這並不是一個可變數組,你只是在寫它。在數組上使用mutableCopy。 – Cameron
@DeepakR聲明無關緊要。 Objective-C是動態的。 – 2013-04-12 20:05:50