Skip to content

NSDictionary

NSDictionary 是不可变的键值集合类型。常见于 API 返回 NSDictionary(例如 options、headerFields、配置对象等)。

返回空字典。

static dictionary(): NSDictionary

Return Value:

  • NSDictionary: 空字典实例。

从单键值对创建字典。

static dictionaryWithObjectForKey(object: any, key: any): NSDictionary

Parameters:

NameTypeDescription
objectany值。
keyany键(需支持 NSCopying)。

Return Value:

  • NSDictionary: 新字典。

从已有字典拷贝创建。

static dictionaryWithDictionary(dict: NSDictionary): NSDictionary

Parameters:

NameTypeDescription
dictNSDictionary源字典。

Return Value:

  • NSDictionary: 新字典。

从键数组与值数组创建。

static dictionaryWithObjectsForKeys(objects: NSArray, keys: NSArray): NSDictionary

Parameters:

NameTypeDescription
objectsNSArray值数组。
keysNSArray键数组。

Return Value:

  • NSDictionary: 新字典。

从可变参数键值对创建(firstObject, firstKey, …)。

static dictionaryWithObjectsAndKeys(firstObject: any, firstKey: any, ...args: any[]): NSDictionary

Parameters:

NameTypeDescription
firstObjectany第一个值。
firstKeyany第一个键。
...argsany[]其余键值交替。

Return Value:

  • NSDictionary: 新字典。

从 plist 文件路径创建。

static dictionaryWithContentsOfFile(path: string): any

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • any: 解析得到的字典或 null。

从 URL 创建。

static dictionaryWithContentsOfURL(url: NSURL): any

Parameters:

NameTypeDescription
urlNSURL资源 URL。

Return Value:

  • any: 解析得到的字典或 null。

键值对个数。

count(): number

Return Value:

  • number: 字典大小。

所有键组成的数组。

allKeys(): NSArray

Return Value:

  • NSArray: 键数组。

所有值组成的数组。

allValues(): NSArray

Return Value:

  • NSArray: 值数组。

按键取值。

objectForKey(key: any): any

Parameters:

NameTypeDescription
keyany键。

Return Value:

  • any: 对应值或 undefined。

下标访问(同 objectForKey)。

objectForKeyedSubscript(key: any): any

Parameters:

NameTypeDescription
keyany键。

Return Value:

  • any: 对应值或 undefined。

按键对应值的排序结果返回键数组。

keysSortedByValueUsingSelector(comparator: any): NSArray

Parameters:

NameTypeDescription
comparatorany比较方法。

Return Value:

  • NSArray: 排序后的键数组。

是否与另一字典内容相等。

isEqualToDictionary(otherDictionary: NSDictionary): boolean

Parameters:

NameTypeDescription
otherDictionaryNSDictionary另一字典。

Return Value:

  • boolean: 是否相等。

返回字典的字符串描述。

description(): string

Return Value:

  • string: 描述字符串。

按 locale 返回描述。

descriptionWithLocale(locale: any): string

Parameters:

NameTypeDescription
localeanylocale。

Return Value:

  • string: 描述字符串。

按 locale 与缩进返回描述。

descriptionWithLocaleIndent(locale: any, level: number): string

Parameters:

NameTypeDescription
localeanylocale。
levelnumber缩进层级。

Return Value:

  • string: 描述字符串。

键的枚举器。

keyEnumerator(): NSEnumerator

Return Value:

  • NSEnumerator: 键枚举器。

值的枚举器。

objectEnumerator(): NSEnumerator

Return Value:

  • NSEnumerator: 值枚举器。

用 block 遍历键值对。

enumerateKeysAndObjectsUsingBlock(block: (key: any, obj: any, stop: any) => void): void

Parameters:

NameTypeDescription
block(key, obj, stop) => void每对调用的回调。

Return Value:

  • 无。

写入 plist 文件。

writeToFileAtomically(path: string, useAuxiliaryFile: boolean): boolean

Parameters:

NameTypeDescription
pathstring文件路径。
useAuxiliaryFileboolean是否先写临时再替换。

Return Value:

  • boolean: 是否成功。

写入 URL。

writeToURLAtomically(url: NSURL, atomically: boolean): boolean

Parameters:

NameTypeDescription
urlNSURL目标 URL。
atomicallyboolean是否原子写入。

Return Value:

  • boolean: 是否成功。
  • NSMutableDictionary — 可变字典
  • NSArray
头文件 API 清单

正在加载…

协议:,来源: