API参考Foundation
NSMutableDictionary
可变键值集合(可增删改的字典/映射)。
NSMutableDictionary 是可变字典类型,用于构造与更新键值对集合。
类成员 (Class members)
dictionaryWithCapacity
预分配容量创建。
static dictionaryWithCapacity(numItems: number): NSMutableDictionaryParameters:
| Name | Type | Description |
|---|---|---|
numItems | number | 初始容量。 |
Return Value:
NSMutableDictionary: 新字典。
dictionaryWithSharedKeySet
使用 sharedKeySet 创建字典(用于大量相同 key 的字典以提升性能)。
static dictionaryWithSharedKeySet(sharedKeySet: any): NSMutableDictionarysharedKeySetForKeys
为 keys 生成 sharedKeySet。
static sharedKeySetForKeys(keys: NSArray): any注:
NSMutableDictionary的工厂方法在插件环境的导出范围较小;请以本页底部的「头文件 API 清单」为准。
实例成员 (Instance members)
setObjectForKey
设置键值对。
setObjectForKey(anObject: any, aKey: any): voidParameters:
| Name | Type | Description |
|---|---|---|
anObject | any | 值。 |
aKey | any | 键。 |
Return Value:
- 无。
setObjectForKeyedSubscript
下标形式设置键值对。
setObjectForKeyedSubscript(obj: any, key: any): voidParameters:
| Name | Type | Description |
|---|---|---|
obj | any | 值。 |
key | any | 键。 |
Return Value:
- 无。
removeObjectForKey
移除指定键的条目。
removeObjectForKey(aKey: any): voidParameters:
| Name | Type | Description |
|---|---|---|
aKey | any | 键。 |
Return Value:
- 无。
removeAllObjects
清空字典。
removeAllObjects(): voidReturn Value:
- 无。
addEntriesFromDictionary
将另一字典所有条目合并进来。
addEntriesFromDictionary(otherDictionary: NSDictionary): voidParameters:
| Name | Type | Description |
|---|---|---|
otherDictionary | NSDictionary | 源字典。 |
Return Value:
- 无。
setDictionary
用另一字典替换全部内容。
setDictionary(otherDictionary: NSDictionary): voidParameters:
| Name | Type | Description |
|---|---|---|
otherDictionary | NSDictionary | 源字典。 |
Return Value:
- 无。
removeObjectsForKeys
移除给定键数组中的键对应条目。
removeObjectsForKeys(keyArray: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
keyArray | NSArray | 要移除的键数组。 |
Return Value:
- 无。
访问与枚举(同 NSDictionary)
objectForKey(key)、allKeys()、allValues()、enumerateKeysAndObjectsUsingBlock(block) 等用法与 NSDictionary 一致。