NSArray
NSArray 是不可变的有序集合类型。在插件环境中,它的语义与系统同名类型一致;你主要会在各种 API 返回值(例如节点列表、搜索结果、comments 等)中遇到它。
类成员 (Class members)
Section titled “类成员 (Class members)”返回空数组。
static array(): NSArrayReturn Value:
NSArray: 空数组实例。
arrayWithObject
Section titled “arrayWithObject”从单个元素创建数组。
static arrayWithObject(anObject: any): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 唯一元素。 |
Return Value:
NSArray: 包含该元素的数组。
arrayWithObjectsCount
Section titled “arrayWithObjectsCount”从 C 数组与长度创建。
static arrayWithObjectsCount(objects: any, cnt: number): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
objects | any | 元素序列。 |
cnt | number | 元素个数。 |
Return Value:
NSArray: 新数组。
arrayWithObjects
Section titled “arrayWithObjects”从可变参数创建数组。
static arrayWithObjects(firstObj: any, ...args: any[]): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
firstObj | any | 第一个元素。 |
...args | any[] | 其余元素。 |
Return Value:
NSArray: 新数组。
arrayWithArray
Section titled “arrayWithArray”从已有数组拷贝创建。
static arrayWithArray(array: NSArray): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
array | NSArray | 源数组。 |
Return Value:
NSArray: 新数组。
arrayWithContentsOfFile
Section titled “arrayWithContentsOfFile”从 plist 文件路径创建。
static arrayWithContentsOfFile(path: string): anyParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件路径。 |
Return Value:
any: 解析得到的数组或 null。
arrayWithContentsOfURL
Section titled “arrayWithContentsOfURL”从 URL 创建。
static arrayWithContentsOfURL(url: NSURL): anyParameters:
| Name | Type | Description |
|---|---|---|
url | NSURL | 资源 URL。 |
Return Value:
any: 解析得到的数组或 null。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”元素个数。
count(): numberReturn Value:
number: 数组长度。
objectAtIndex
Section titled “objectAtIndex”按下标取元素。
objectAtIndex(index: number): anyParameters:
| Name | Type | Description |
|---|---|---|
index | number | 索引。 |
Return Value:
any: 该位置元素。
objectAtIndexedSubscript
Section titled “objectAtIndexedSubscript”下标访问(同 objectAtIndex)。
objectAtIndexedSubscript(idx: number): anyParameters:
| Name | Type | Description |
|---|---|---|
idx | number | 索引。 |
Return Value:
any: 该位置元素。
firstObject
Section titled “firstObject”第一个元素。
firstObject(): anyReturn Value:
any: 首元素或 undefined。
lastObject
Section titled “lastObject”最后一个元素。
lastObject(): anyReturn Value:
any: 末元素或 undefined。
containsObject
Section titled “containsObject”是否包含某元素。
containsObject(anObject: any): booleanParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 待查找元素。 |
Return Value:
boolean: 是否包含。
indexOfObject
Section titled “indexOfObject”查找元素首次出现的下标。
indexOfObject(anObject: any): numberParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 待查找元素。 |
Return Value:
number: 下标,未找到为 NSNotFound。
indexOfObjectInRange
Section titled “indexOfObjectInRange”在范围内查找元素下标。
indexOfObjectInRange(anObject: any, range: any): numberParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 待查找元素。 |
range | any | 范围(如 { location, length })。 |
Return Value:
number: 下标,未找到为 NSNotFound。
indexOfObjectIdenticalTo
Section titled “indexOfObjectIdenticalTo”按引用相等查找下标。
indexOfObjectIdenticalTo(anObject: any): numberParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 待查找对象。 |
Return Value:
number: 下标,未找到为 NSNotFound。
indexOfObjectIdenticalToInRange
Section titled “indexOfObjectIdenticalToInRange”在范围内按引用相等查找。
indexOfObjectIdenticalToInRange(anObject: any, range: any): numberParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 待查找对象。 |
range | any | 范围。 |
Return Value:
number: 下标,未找到为 NSNotFound。
isEqualToArray
Section titled “isEqualToArray”是否与另一数组内容相等。
isEqualToArray(otherArray: NSArray): booleanParameters:
| Name | Type | Description |
|---|---|---|
otherArray | NSArray | 另一数组。 |
Return Value:
boolean: 是否相等。
firstObjectCommonWithArray
Section titled “firstObjectCommonWithArray”与另一数组的任一公共元素。
firstObjectCommonWithArray(otherArray: NSArray): anyParameters:
| Name | Type | Description |
|---|---|---|
otherArray | NSArray | 另一数组。 |
Return Value:
any: 首个公共元素或 undefined。
objectsAtIndexes
Section titled “objectsAtIndexes”按索引集取多个元素。
objectsAtIndexes(indexes: NSIndexSet): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
indexes | NSIndexSet | 索引集合。 |
Return Value:
NSArray: 对应元素组成的数组。
subarrayWithRange
Section titled “subarrayWithRange”取子数组。
subarrayWithRange(range: any): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围(如 { location, length })。 |
Return Value:
NSArray: 子数组。
arrayByAddingObject
Section titled “arrayByAddingObject”在末尾添加一个元素得到新数组。
arrayByAddingObject(anObject: any): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 要添加的元素。 |
Return Value:
NSArray: 新数组。
arrayByAddingObjectsFromArray
Section titled “arrayByAddingObjectsFromArray”拼接另一数组得到新数组。
arrayByAddingObjectsFromArray(otherArray: NSArray): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
otherArray | NSArray | 要拼接的数组。 |
Return Value:
NSArray: 新数组。
sortedArrayUsingDescriptors
Section titled “sortedArrayUsingDescriptors”按排序描述符排序得到新数组。
sortedArrayUsingDescriptors(sortDescriptors: NSArray): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
sortDescriptors | NSArray | 排序描述符数组。 |
Return Value:
NSArray: 排序后的新数组。
sortedArrayUsingSelector
Section titled “sortedArrayUsingSelector”按 selector 比较排序得到新数组。
sortedArrayUsingSelector(comparator: any): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
comparator | any | 比较方法。 |
Return Value:
NSArray: 排序后的新数组。
sortedArrayUsingFunctionContext
Section titled “sortedArrayUsingFunctionContext”用 C 函数与 context 排序得到新数组。
sortedArrayUsingFunctionContext(comparator: any, context: any): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
comparator | any | 比较函数。 |
context | any | 上下文。 |
Return Value:
NSArray: 排序后的新数组。
sortedArrayUsingFunctionContextHint
Section titled “sortedArrayUsingFunctionContextHint”带 hint 的排序得到新数组。
sortedArrayUsingFunctionContextHint(comparator: any, context: any, hint: any): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
comparator | any | 比较函数。 |
context | any | 上下文。 |
hint | any | 排序 hint。 |
Return Value:
NSArray: 排序后的新数组。
sortedArrayHint
Section titled “sortedArrayHint”用于高效重排的 hint 数据。
sortedArrayHint(): NSDataReturn Value:
NSData: 排序 hint。
objectEnumerator
Section titled “objectEnumerator”正向枚举器。
objectEnumerator(): NSEnumeratorReturn Value:
NSEnumerator: 正向枚举器。
reverseObjectEnumerator
Section titled “reverseObjectEnumerator”反向枚举器。
reverseObjectEnumerator(): NSEnumeratorReturn Value:
NSEnumerator: 反向枚举器。
enumerateObjectsUsingBlock
Section titled “enumerateObjectsUsingBlock”用 block 遍历元素。
enumerateObjectsUsingBlock(block: (obj: any, idx: number, stop: any) => void): voidParameters:
| Name | Type | Description |
|---|---|---|
block | (obj, idx, stop) => void | 每元素调用的回调。 |
Return Value:
- 无。
componentsJoinedByString
Section titled “componentsJoinedByString”用分隔符拼接为字符串。
componentsJoinedByString(separator: string): stringParameters:
| Name | Type | Description |
|---|---|---|
separator | string | 分隔符。 |
Return Value:
string: 拼接结果。
description
Section titled “description”返回数组的字符串描述。
description(): stringReturn Value:
string: 描述字符串。
descriptionWithLocale
Section titled “descriptionWithLocale”按 locale 返回描述。
descriptionWithLocale(locale: any): stringParameters:
| Name | Type | Description |
|---|---|---|
locale | any | locale。 |
Return Value:
string: 描述字符串。
descriptionWithLocaleIndent
Section titled “descriptionWithLocaleIndent”按 locale 与缩进返回描述。
descriptionWithLocaleIndent(locale: any, level: number): stringParameters:
| Name | Type | Description |
|---|---|---|
locale | any | locale。 |
level | number | 缩进层级。 |
Return Value:
string: 描述字符串。
getObjectsRange
Section titled “getObjectsRange”将范围内元素写入 C 数组。
getObjectsRange(objects: any, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
objects | any | 目标数组。 |
range | any | 范围。 |
Return Value:
- 无。
makeObjectsPerformSelector
Section titled “makeObjectsPerformSelector”对每个元素调用 selector。
makeObjectsPerformSelector(aSelector: any): voidParameters:
| Name | Type | Description |
|---|---|---|
aSelector | any | 要调用的 selector。 |
Return Value:
- 无。
makeObjectsPerformSelectorWithObject
Section titled “makeObjectsPerformSelectorWithObject”对每个元素调用带参 selector。
makeObjectsPerformSelectorWithObject(aSelector: any, argument: any): voidParameters:
| Name | Type | Description |
|---|---|---|
aSelector | any | 要调用的 selector。 |
argument | any | 参数。 |
Return Value:
- 无。
writeToFileAtomically
Section titled “writeToFileAtomically”写入 plist 文件。
writeToFileAtomically(path: string, useAuxiliaryFile: boolean): booleanParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件路径。 |
useAuxiliaryFile | boolean | 是否先写临时再替换。 |
Return Value:
boolean: 是否成功。
writeToURLAtomically
Section titled “writeToURLAtomically”写入 URL。
writeToURLAtomically(url: NSURL, atomically: boolean): booleanParameters:
| Name | Type | Description |
|---|---|---|
url | NSURL | 目标 URL。 |
atomically | boolean | 是否原子写入。 |
Return Value:
boolean: 是否成功。
NSMutableArray— 可变数组- NSEnumerator、NSIndexSet