Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 数组中的数组项替换_Objective C_Ios_Arrays_Xcode - Fatal编程技术网

Objective c 数组中的数组项替换

Objective c 数组中的数组项替换,objective-c,ios,arrays,xcode,Objective C,Ios,Arrays,Xcode,我有一个数组列表,其中的每个元素都是数组。我知道,这有点奇怪,但这是必要的。所以,我需要替换数组中的元素。我试过这个: for (int i = 0; i < [myArray count]; i++) { for (int j = 0; j < [[myArray objectAtIndex:i] count]; j++) { for (int k = 0; k < [[[myArray objectAtIndex:i] objectAtIndex:j

我有一个数组列表,其中的每个元素都是数组。我知道,这有点奇怪,但这是必要的。所以,我需要替换数组中的元素。我试过这个:

for (int i = 0; i < [myArray count]; i++) {
    for (int j = 0; j < [[myArray objectAtIndex:i] count]; j++) {
        for (int k = 0; k < [[[myArray objectAtIndex:i] objectAtIndex:j] count]; k++) {
            [[[myArray objectAtIndex:i] objectAtIndex:j] replaceObjectAtIndex:k withObject:@"Some_string"];
        }
    }
}
for(int i=0;i<[myArray count];i++){
对于(int j=0;j<[[myArray objectAtIndex:i]count];j++){
对于(int k=0;k<[[myArray objectAtIndex:i]objectAtIndex:j]计数];k++){
[[[myArray objectAtIndex:i]objectAtIndex:j]replaceObjectAtIndex:k with object:@“Some_string”];
}
}
}
并且由于未捕获的异常“NSInvalidArgumentException”而终止应用程序时出错,原因:'-[\uu NSArrayI replaceObjectAtIndex:withObject::]:无法识别的选择器发送到实例。但是我可以记录这个元素,例如,
NSLog(@“%@,[NSString stringWithFormat:@”%@,[[[myArray objectAtIndex:0]objectAtIndex:0]objectAtIndex:0]]),没关系


可能是什么?谢谢您的帮助。

您的数组是
NSMutableArray
的实例,而不是不可变的
NSArray

是。我应该把它转换成NSMutableArray吗?更新:我通过
NSMutableArray*myMutArray=[myArray mutableCopy]
从myArray创建可变数组,但这没有帮助。我认为问题是您需要让内部数组可变。因此,不要使用[myArray mutableCopy]执行
myMutArray=[NSMutableArray]
,而是通过myArray,为每个子阵列将其mutableCopy添加到新的
myMutArray
。抱歉,有点误解
myArray
最初是NSArray的实例@mrueg,好的,谢谢,我会试试。@mrueg
mutableCopy
保证返回一个可变实例。