公告
财富商城
积分规则
提问
发文
2019-02-02 18:52发布
手持菜刀,她持情操
How can an object be added at a specific index of an NSMutableArray?
NSMutableArray
How is an object added to the front of the array?
Updated for Swift 3:
If you want to Add an object at a specific index of a NSMutableArray, use below a simple line of code:
self.yourMutableArrayName.insert(<#T##newElement: String##String#>, at: <#T##Int#>)
Example: if you want to add string: "Nature" at index: 3
var str = "Nature" self.yourMutableArrayName.insert(str, at: 3)
// Enjoy..!
[myMutableArray insertObject:myObject atIndex:42];
To add an object to the front of the array, use 0 as the index:
[myMutableArray insertObject:myObject atIndex:0];
Take a look at the insertObject:atIndex: method of the NSMutableArray class. Adding to the "front" of the array implies index 0.
insertObject:atIndex:
For example:
NSMutableArray * array = [[NSMutableArray alloc] initWithCapacity:3]; [array addObject:@"b"]; // Contains "b" [array insertObject:@"a" atIndex:0]; // Contains "a", "b" [array insertObject:@"c" atIndex:2]; // Contains "a", "b", "c"
最多设置5个标签!
If you want to Add an object at a specific index of a NSMutableArray, use below a simple line of code:
Example: if you want to add string: "Nature" at index: 3
// Enjoy..!
To add an object to the front of the array, use 0 as the index:
Take a look at the
insertObject:atIndex:
method of the NSMutableArray class. Adding to the "front" of the array implies index 0.For example: