NSInternalInconsistencyException原因:' - [__ NSCFArray replaceObjectAtIndex:withObject:]:mutating方法发送到不可变对象'

时间:2013-04-12 19:58:03

标签: iphone ios

你可以帮我解决以下错误:

由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:' - [__ NSCFArray replaceObjectAtIndex:withObject:]:mutating方法发送到不可变对象'

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++;
            }

2 个答案:

答案 0 :(得分:6)

假设array_Infoself.array_Info属性的支持变量,您应该将第二行更改为:

array_Info = [[dict_Temp objectForKey:@"Children"] mutableCopy];

这将为您提供replaceObjectAtIndex:withObject:电话所需的可变数组。

答案 1 :(得分:2)

似乎self.array_Info是一个不可变数组。让它变得可变。