NSMutableArray
NSMutableArray 是可变数组类型,用于在原数组基础上增删元素、排序等。
类成员 (Class members)
Section titled “类成员 (Class members)”arrayWithCapacity
Section titled “arrayWithCapacity”预分配容量创建。
static arrayWithCapacity(numItems: number): NSMutableArrayParameters:
| Name | Type | Description |
|---|---|---|
numItems | number | 初始容量。 |
Return Value:
NSMutableArray: 新数组。
注:除
arrayWithCapacity(...)外,其它常见工厂方法在最新头文件导出清单中未暴露;请以本页底部的「头文件 API 清单」为准。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”addObject
Section titled “addObject”在末尾添加元素。
addObject(anObject: any): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要添加的元素。 |
Return Value:
- 无。
addObjectsFromArray
Section titled “addObjectsFromArray”在末尾追加另一数组所有元素。
addObjectsFromArray(otherArray: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
otherArray | NSArray | 要追加的数组。 |
Return Value:
- 无。
insertObjectAtIndex
Section titled “insertObjectAtIndex”在指定下标插入元素。
insertObjectAtIndex(anObject: any, index: number): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要插入的元素。 |
index | number | 下标。 |
Return Value:
- 无。
removeLastObject
Section titled “removeLastObject”移除最后一个元素。
removeLastObject(): voidReturn Value:
- 无。
removeObject
Section titled “removeObject”移除所有与给定对象相等的元素。
removeObject(anObject: any): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要移除的对象。 |
Return Value:
- 无。
removeObjectAtIndex
Section titled “removeObjectAtIndex”移除指定下标的元素。
removeObjectAtIndex(index: number): voidParameters:
| Name | Type | Description |
|---|---|---|
index | number | 下标。 |
Return Value:
- 无。
removeObjectIdenticalTo
Section titled “removeObjectIdenticalTo”移除所有与给定对象引用相等的元素。
removeObjectIdenticalTo(anObject: any): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要移除的对象。 |
Return Value:
- 无。
removeObjectInRange
Section titled “removeObjectInRange”在范围内移除与给定对象相等的元素。
removeObjectInRange(anObject: any, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要移除的对象。 |
range | any | 范围。 |
Return Value:
- 无。
removeObjectIdenticalToInRange
Section titled “removeObjectIdenticalToInRange”在范围内移除与给定对象引用相等的元素。
removeObjectIdenticalToInRange(anObject: any, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要移除的对象。 |
range | any | 范围。 |
Return Value:
- 无。
removeObjectsAtIndexes
Section titled “removeObjectsAtIndexes”移除索引集中的下标对应元素。
removeObjectsAtIndexes(indexes: NSIndexSet): voidParameters:
| Name | Type | Description |
|---|---|---|
indexes | NSIndexSet | 要移除的下标集合。 |
Return Value:
- 无。
removeObjectsInArray
Section titled “removeObjectsInArray”移除与另一数组中元素相等的所有元素。
removeObjectsInArray(otherArray: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
otherArray | NSArray | 要移除的元素所在数组。 |
Return Value:
- 无。
removeAllObjects
Section titled “removeAllObjects”清空数组。
removeAllObjects(): voidReturn Value:
- 无。
replaceObjectAtIndexWithObject
Section titled “replaceObjectAtIndexWithObject”替换指定下标的元素。
replaceObjectAtIndexWithObject(index: number, anObject: any): voidParameters:
| Name | Type | Description |
|---|---|---|
index | number | 下标。 |
anObject | any | 新元素。 |
Return Value:
- 无。
replaceObjectsAtIndexesWithObjects
Section titled “replaceObjectsAtIndexesWithObjects”按索引集替换为给定数组中的元素。
replaceObjectsAtIndexesWithObjects(indexes: NSIndexSet, objects: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
indexes | NSIndexSet | 下标集合。 |
objects | NSArray | 新元素数组。 |
Return Value:
- 无。
replaceObjectsInRangeWithObjectsFromArray
Section titled “replaceObjectsInRangeWithObjectsFromArray”用另一数组替换范围内元素。
replaceObjectsInRangeWithObjectsFromArray(range: any, otherArray: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围。 |
otherArray | NSArray | 源数组。 |
Return Value:
- 无。
replaceObjectsInRangeWithObjectsFromArrayRange
Section titled “replaceObjectsInRangeWithObjectsFromArrayRange”用另一数组的指定范围替换当前范围。
replaceObjectsInRangeWithObjectsFromArrayRange(range: any, otherArray: NSArray, otherRange: any): voidParameters:
| Name | Type | Description |
|---|---|---|
range | any | 当前范围。 |
otherArray | NSArray | 源数组。 |
otherRange | any | 源范围。 |
Return Value:
- 无。
setArray
Section titled “setArray”用另一数组替换全部内容。
setArray(otherArray: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
otherArray | NSArray | 源数组。 |
Return Value:
- 无。
exchangeObjectAtIndexWithObjectAtIndex
Section titled “exchangeObjectAtIndexWithObjectAtIndex”交换两个下标的元素。
exchangeObjectAtIndexWithObjectAtIndex(idx1: number, idx2: number): voidParameters:
| Name | Type | Description |
|---|---|---|
idx1 | number | 下标一。 |
idx2 | number | 下标二。 |
Return Value:
- 无。
sortUsingDescriptors
Section titled “sortUsingDescriptors”按排序描述符原地排序。
sortUsingDescriptors(sortDescriptors: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
sortDescriptors | NSArray | 排序描述符数组。 |
Return Value:
- 无。
sortUsingSelector
Section titled “sortUsingSelector”按 selector 比较原地排序。
sortUsingSelector(comparator: any): voidParameters:
| Name | Type | Description |
|---|---|---|
comparator | any | 比较方法。 |
Return Value:
- 无。
sortUsingFunctionContext
Section titled “sortUsingFunctionContext”用 C 函数与 context 原地排序。
sortUsingFunctionContext(comparator: any, context: any): voidParameters:
| Name | Type | Description |
|---|---|---|
comparator | any | 比较函数。 |
context | any | 上下文。 |
Return Value:
- 无。
sortUsingComparator
Section titled “sortUsingComparator”按 comparator 块原地排序。
sortUsingComparator(cmptr: any): voidParameters:
| Name | Type | Description |
|---|---|---|
cmptr | any | 比较块。 |
Return Value:
- 无。
sortWithOptionsUsingComparator
Section titled “sortWithOptionsUsingComparator”带选项的 comparator 排序。
sortWithOptionsUsingComparator(opts: number, cmptr: any): voidParameters:
| Name | Type | Description |
|---|---|---|
opts | number | 排序选项。 |
cmptr | any | 比较块。 |
Return Value:
- 无。
访问与查询(同 NSArray)
Section titled “访问与查询(同 NSArray)”count()、objectAtIndex(index)、objectAtIndexedSubscript(idx)、firstObject()、lastObject()、containsObject(anObject)、indexOfObject(anObject)、subarrayWithRange(range) 等用法与 NSArray 一致。
- NSArray
NSIndexSet、NSSortDescriptor(如可用)