Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
Iphone 向NSMutableArray目标c中的每个元素添加一个常量_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 向NSMutableArray目标c中的每个元素添加一个常量

Iphone 向NSMutableArray目标c中的每个元素添加一个常量,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我试图向NSMutableArray中的每个元素添加一个整数,但找不到这样做的方法。例如,尝试向[3,4,7]等元素数组中添加5以获得[8,9,12] 任何帮助都会很好。谢谢。假设里面的项目是NSNumber对象,您可以这样做: for (int i = 0 ; i != arr.count ; i++) { NSNumber *n = [arr objectAtIndex:i]; [arr replaceObjectAtIndex:i wi

我试图向NSMutableArray中的每个元素添加一个整数,但找不到这样做的方法。例如,尝试向[3,4,7]等元素数组中添加5以获得[8,9,12]


任何帮助都会很好。谢谢。

假设里面的项目是
NSNumber
对象,您可以这样做:

for (int i = 0 ; i != arr.count ; i++) {
    NSNumber *n = [arr objectAtIndex:i];
    [arr replaceObjectAtIndex:i
                   withObject:[NSNumber numberWithInt:5 + [n intValue]]
    ];
}

循环整个数组,并将当前对象替换为“对象值”+5

For (int i=0, i<[myArray count], i++ {
      NSNumber *tmpNum = [myArray objectAtIndex:i];
      int tmpInt = [tmpNum intValue];
      tmpInt = tmpInt+5;
      tmpNum = [NSNumber numberWithInt:tmpInt];
      [myArray replaceObjectAtIndex:i withObject:tmpNum];
}
For(int i=0,i