iphone - NSInternalInconsistencyException 原因 : '-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'

标签 iphone ios

你能帮我解决以下错误吗:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object”

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

最佳答案

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

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

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

关于iphone - NSInternalInconsistencyException 原因 : '-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15979862/

相关文章:

iphone - 编译 iPhone 应用程序时综合属性错误

ios - 在 objective-c 中动态命名标签

objective-c - 使用 UIImagePickerController 选择图像后,照片库 View 停留在屏幕上

ios - 如何从 native 应用程序链接到手机设置

ios - 当键盘弹出时将原点移动到顶部时会出现黑色

iOS - 后台 BLE 扫描随机卡住

iphone - iOS 5.0 检测应用程序何时从 Safari.app 中的 URL 重新激活

iphone - iOS 设备方向无视方向锁定

ios - 是否可以在没有 iTunes 或 App Store 的情况下安装 iOS 应用程序?

ios - 如何禁用 UICollectionView 中的选择动画?