xcode IOS:在一个 NSMutableArray 的特定位置添加一个对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5754225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:52:44  来源:igfitidea点击:

IOS: add an object in a specific position of a NSMutableArray

objective-cxcodeiosnsmutablearray

提问by cyclingIsBetter

In my project I want to add an object in a specific position of a NSMutableArray, example:

在我的项目中,我想在 NSMutableArray 的特定位置添加一个对象,例如:

if(index ==1) {
// I want add object at position 1 of NSMutableArray
}

if(index == 2) {
// I want add object at position 2 of NSMutableArray
}
...
if(index == 15) {
// I want add object at position 15 of NSMutableArray
}

How can I do?

我能怎么做?

回答by extremeboredom

use [array insertObject:object atIndex:index];

[array insertObject:object atIndex:index];

回答by kubi

You could use a C array for this.

您可以为此使用 C 数组。

id objects[15];

objects[index] = yourObject;