NSDictionary 字典

前言

  • NSDictionary 字典

    • Objective-C

      1
      2
      @interface NSDictionary<__covariant KeyType, __covariant ObjectType> : NSObject <NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration>
      @interface NSMutableDictionary<KeyType, ObjectType> : NSDictionary<KeyType, ObjectType>
    • Swift

      1
      public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration
    • 字典只能存储 OC 对象,不能存储 C 语言中的基本数据类型,也不能存储 nil 。字典中的键必须是单值的,通常它们是字符串。

    • 字典对象是无序的,第一个放到词典中的键-对象对并不一定是第一个取出。

    • Xcode 7 对系统中常用的一系列容器类型都增加了泛型支持(),有了泛型后就可以指定容器类中对象的类型了。假如向泛型容器中加入错误的对象,编译器会报警告。

      1
      2
      __covariant:协变性,子类型可以强转到父类型(里氏替换原则)。
      __contravariant:逆变性,父类型可以强转到子类型。
    • 不指定泛型类型的对象可以和任意泛型类型转化,但指定了泛型类型后,两个不同类型间是不可以强转的,假如你希望主动控制转化关系,就需要使用泛型的协变性和逆变性修饰符。

  • Dictionary 字典

    • Swift

      1
      public struct Dictionary<Key : Hashable, Value> : CollectionType, DictionaryLiteralConvertible
    • 字典用于存储无序的数据元素值,它可以存储任何类型的元素,甚至可以将数组作为字典的元素。

1、不可变字典的创建

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    // 直接创建不可变字典

    // 字典中的 key 和 value 成对出现
    NSDictionary *dic1 = @{@"key1":@"value1", @"key2":@"value2"};

    // 对象方法创建

    NSDictionary *dic2 = [[NSDictionary alloc] init];

    // 和 dic1 的地址不相同
    NSDictionary *dic3 = [[NSDictionary alloc] initWithDictionary:dic1];

    NSDictionary *dic4 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
    NSDictionary *dic5 = [[NSDictionary alloc] initWithObjects:@[@"value1", @"value2", @"value3",]
    forKeys:@[@"key1", @"key2", @"key3"]];

    // 类方法创建

    NSDictionary *dic6 = [NSDictionary dictionary];

    // 和 dic1 的地址不相同
    NSDictionary *dic7 = [NSDictionary dictionaryWithDictionary:dic1];

    NSDictionary *dic8 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
    NSDictionary *dic9 = [NSDictionary dictionaryWithObject:@"value1" forKey:@"key1"];
    NSDictionary *dic10 = [NSDictionary dictionaryWithObjects:@[@"value1", @"value2", @"value3",]
    forKeys:@[@"key1", @"key2", @"key3"]];

    // 从 文件 创建字符串

    NSString *path = [NSHomeDirectory() stringByAppendingString:@"/Desktop/test.txt"];

    NSDictionary *dic11 = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSDictionary *dic12 = [NSDictionary dictionaryWithContentsOfFile:path];

    // 从 Url 创建字符串

    /*
    file:// 文件前缀
    */

    NSURL *url = [NSURL URLWithString:[@"file://" stringByAppendingString:[NSHomeDirectory()
    stringByAppendingString:@"/Desktop/test.txt"]]];

    NSDictionary *dic13 = [[NSDictionary alloc] initWithContentsOfURL:url];
    NSDictionary *dic14 = [NSDictionary dictionaryWithContentsOfURL:url];

    // 泛型创建

    NSDictionary<NSString *, NSNumber *> *dic15 = @{@"key1":@3, @"key2":@5};

2、NSDictionary/Dictionary 字典中元素个数的计算

  • Objective-C

    1
    2
    3
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

    NSUInteger length = [dic count];
  • Swift

    1
    2
    3
    4
    5
    // Dictionary 或 NSDictionary 型字典

    let dic = ["key1":1, "key2":2, "key3":3, "key4":4]

    let length: Int = dic.count

3、NSDictionary/Dictionary 通过 key 找对应的 value

3.1 NSDictionary 通过 key 找对应的 value

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

    // 通过 key 找对应的 value
    NSLog(@"%@", [dic objectForKey:@"key1"]);

    // 以下标的方式找 key 找对应的 value
    NSLog(@"%@", dic[@"key2"]);

    // key 没有对应的 value 时用 notFoundMarker 参数代替
    NSArray *arr = [dic objectsForKeys:@[@"key1", @"key1", @"key3"] notFoundMarker:@"not-Found"];
  • Swift

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    let nsDic: NSDictionary = NSDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    // 获取字典中指定 key 对应的值
    let value2: AnyObject? = nsDic["key2"]

    // 获取字典中指定 key 对应的值
    let value3: AnyObject? = nsDic.objectForKey("key2")

    // 获取字典中指定 key 对应的值,key 的值不存在时返回指定的字符串
    let value4 = nsDic.objectsForKeys(["key3", "key4", "key5"], notFoundMarker: "not found")

3.2 Dictionary 通过 key 找对应的 value

  • Swift

    1
    2
    3
    4
    var dic: Dictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    // 获取字典中指定 key 对应的值
    let value1 = dic["key2"]

4、NSDictionary 通过 value 找对应的 key

  • Objective-C

    1
    2
    3
    4
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", 
    @"key2", @"value2", @"key3", nil];

    NSLog(@"%@", [dic allKeysForObject:@"value2"]);
  • Swift

    1
    2
    3
    let nsDic: NSDictionary = NSDictionary(dictionary: ["key1":1, "key2":3, "key3":3, "key4":4])

    let keys: AnyObject = nsDic.allKeysForObject(3)

5、NSDictionary/Dictionary 字典中所有 key 的获取

5.1 NSDictionary 字典中所有 key 的获取

  • Objective-C

    1
    2
    3
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

    NSLog(@"%@", [dic allKeys]);
  • Swift

    1
    2
    3
    let nsDic: NSDictionary = NSDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    let keys2 = nsDic.allKeys

5.2 Dictionary 字典中所有 key 的获取

  • Swift

    1
    2
    3
    let dic: Dictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    let keys1 = dic.keys

6、NSDictionary/Dictionary 字典中所有 value 的获取

6.1 NSDictionary 字典中所有 value 的获取

  • Objective-C

    1
    2
    3
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

    NSLog(@"%@", [dic allValues]);
  • Swift

    1
    2
    3
    let nsDic: NSDictionary = NSDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    let values2 = nsDic.allValues

6.2 Dictionary 字典中所有 value 的获取

  • Swift

    1
    2
    3
    let dic: Dictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    let values1 = dic.values

7、NSMutableDictionary/Dictionary 可变字典的创建

7.1 NSMutableDictionary 可变字典的创建

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    9
    // 对象方法创建

    // 创建指定长度的字典,预先分配空间,提高效率,实际长度可大于指定长度
    NSMutableDictionary *dic1 = [[NSMutableDictionary alloc] initWithCapacity:0];

    // 类方法创建

    // 创建指定长度的字典,预先分配空间,提高效率,实际长度可大于指定长度
    NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithCapacity:0];
  • Swift

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    let swiftDictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    let nsdic1: NSDictionary = swiftDictionary
    let nsdic2: NSDictionary = swiftDictionary as NSDictionary

    let nsdic3: NSDictionary = NSDictionary(dictionary: swiftDictionary)
    let nsdic4: NSDictionary = NSDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    let nsdic5: NSDictionary = NSDictionary(object: "nsdic5", forKey: "key1")
    let nsdic6: NSDictionary = NSDictionary(objects: ["nsdic6", 2], forKeys: ["key1", "key2"])
    let nsdic7: NSDictionary = NSDictionary(dictionaryLiteral: ("key1", "nsdic7"),
    ("key2", 2),
    ("key3", 3),
    ("key4", 4))

    // 从 文件 创建字符串
    let nsdic8: NSDictionary? = NSDictionary(contentsOfFile: NSHomeDirectory() + "/Desktop/test.txt")

    // 从 Url 创建字符串
    let nsdic9: NSDictionary? = NSDictionary(contentsOfURL: NSURL(fileURLWithPath: NSHomeDirectory() + "/Desktop/test.txt"))

7.2 Dictionary 字典的创建

  • Swift

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    // 创建字典变量,指定数据类型为 Int 型
    let dic1 = [String:Int]()

    // 创建字典变量,Dictionary<String, Int> 等价于 [String:Int]
    let dic2 = Dictionary<String, Int>()

    // 创建字典变量,不指定数据类型
    let dic3: Dictionary = ["key1":1, "key2":2]

    // 创建字典变量,指定数据类型为 Int 型
    let dic4: Dictionary<String, Int> = ["key1":1, "key2":2, "key3":3]

    // 创建字典变量,不指定数据类型
    let dic5 = ["key1":1, "key2":2, "key3":3, "key4":4]

    // 创建指定数据类型的字典
    let dic6: [String:Int] = ["key1":1, "key2":2, "key3":3, "key4":4]

    // 创建指定数据类型的字典
    let dic7: [String:AnyObject] = ["key1":1, "key2":2, "key3":"value3", "key4":4]

8、NSMutableDictionary/Dictionary 字典中键值对的追加

8.1 NSMutableDictionary 字典中键值对的追加

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", nil];

    // 向字典末尾追加一个元素(key 值为新增的,若 key 值已存在则为修改对应的 value 值)
    [dic setObject:@"value2" forKey:@"key2"];

    // 向字典末尾追加一个字典
    NSDictionary *dicAdd = @{@"key3": @"value3"};
    [dic addEntriesFromDictionary:dicAdd];
  • Swift

    1
    2
    3
    4
    5
    6
    7
    let nsDic: NSMutableDictionary = NSMutableDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    // key 不存在时,追加键值对(key 值为新增的,若 key 值已存在则为修改对应的 value 值)
    nsDic["key5"] = 5

    // 向字典末尾追加一个字典
    nsDic.addEntriesFromDictionary(["key6":6, "key7":7])

8.2 Dictionary 字典中键值对的追加

  • Swift

    1
    2
    3
    4
    var dic: Dictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    // key 不存在时,追加键值对(key 值为新增的,若 key 值已存在则为修改对应的 value 值)
    dic["key5"] = 5

9、NSMutableDictionary/Dictionary 字典中元素的删除

9.1 NSMutableDictionary 字典中元素的删除

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    9
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", 
    @"key2", @"value3", @"key3",
    @"value4", @"key4", nil];

    // 删除指定的 key 对应的 value 和 key 值
    [dic removeObjectForKey:@"key3"];

    // 删除所有的 value 和 key 值
    [dic removeAllObjects];
  • Swift

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    let nsDic: NSMutableDictionary = NSMutableDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    // 删除指定 key 对应的值
    nsDic.removeObjectForKey("key2")

    // 删除指定 key 对应的值
    nsDic.removeObjectsForKeys(["key1", "key4"])

    // 删除字典的所有元素
    nsDic.removeAllObjects()

9.2 Dictionary 字典中元素的删除

  • Swift

    1
    2
    3
    4
    5
    6
    7
    var dic: Dictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    // 删除指定 key 对应的值
    dic.removeValueForKey("key2")

    // 删除字典的所有元素
    dic.removeAll(keepCapacity: true)

10、NSMutableDictionary/Dictionary 字典中元素的修改

10.1 NSMutableDictionary 字典中元素的修改

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", 
    @"key2", @"value3", @"key3",
    @"value4", @"key4", nil];

    // 修改已存在的键值(key 值为已经存在的,若 key 值为新增的则为追加对应的 value 值)
    [dic setObject:@"value5" forKey:@"key1"];

    // 修改整个字典(覆盖重写)
    NSDictionary *dic1 = @{@"key10":@"value10"};
    [dic setDictionary:dic1];
  • Swift

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    let nsDic: NSMutableDictionary = NSMutableDictionary(dictionary: ["key1":1, "key2":2, "key3":3, "key4":4])

    // key 存在时,修改其值
    nsDic["key3"] = 33

    // 修改指定的 key 对应的值
    nsDic.setObject(100, forKey: "key4")

    // 修改整个字典
    nsDic.setDictionary(["key6":6, "key7":7])

10.2 Dictionary 字典中元素的修改

  • Swift

    1
    2
    3
    4
    5
    6
    7
    var dic: Dictionary = ["key1":1, "key2":2, "key3":3, "key4":4]

    // key 存在时,修改其值
    dic["key4"] = 100

    // 修改指定的 key 对应的值
    dic.updateValue(44, forKey: "key4")

11、字典遍历

  • for 循环

    • Objective-C

      1
      2
      3
      4
      5
      6
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

      for (int i = 0; i < [dic count]; i++) {

      NSLog(@"%@ = %@", [[dic allKeys] objectAtIndex:i], [dic objectForKey:[[dic allKeys] objectAtIndex:i]]);
      }
  • for…in 循环

    • Objective-C

      1
      2
      3
      4
      5
      6
      7
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

      // 遍历所取出的为 key
      for(id key in dic){

      NSLog(@"%@ = %@", key, [dic objectForKey:key]);
      }
    • Swift

      1
      2
      3
      4
      5
      6
      7
      let nsDic: NSDictionary = NSDictionary(dictionary: ["key1": 1, "key2": 2, "key3": 3, "key4": 4])

      // 遍历出的为 key-value 的元组, key 不需要可以用 _ 替代
      for (_, obj) in nsDic {

      print(obj)
      }
  • Block(闭包)遍历

    • Objective-C

      1
      2
      3
      4
      5
      6
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

      [dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {

      NSLog(@"%@ = %@", key, obj);
      }];
    • Swift

      1
      2
      3
      4
      5
      6
      let nsDic: NSDictionary = NSDictionary(dictionary: ["key1": 1, "key2": 2, "key3": 3, "key4": 4])

      nsDic.enumerateKeysAndObjectsUsingBlock { (key: AnyObject, obj: AnyObject, stop:UnsafeMutablePointer<ObjCBool>) in

      print(obj)
      }
  • 迭代器遍历

    • Objective-C

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];

      // key 迭代器

      NSEnumerator *keyEnumer = [dic keyEnumerator];

      id key = nil;
      while (key = [keyEnumer nextObject]) {
      NSLog(@"%@ = %@", key, [dic objectForKey:key]);
      }

      // 对象迭代器

      NSEnumerator *objEnumer = [dic objectEnumerator];

      id obj = nil;
      while (obj = [objEnumer nextObject]) {
      NSLog(@"%@", obj);
      }
    • Swift

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      let nsDic: NSDictionary = NSDictionary(dictionary: ["key1": 1, "key2": 2, "key3": 3, "key4": 4])

      // key 迭代器

      let keyEnu: NSEnumerator = nsDic.keyEnumerator()

      while let key: AnyObject = keyEnu.nextObject() {

      print(nsDic.objectForKey(key))
      }

      // 对象迭代器

      let objEnu: NSEnumerator = nsDic.objectEnumerator()

      while let obj: AnyObject = objEnu.nextObject() {

      print(obj)
      }

12、字典排序

  • 用指定的方法排序

    • Objective-C

      1
      2
      3
      4
      5
      6
      7
      8
      9
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", 
      @"value3", @"key3", @"value4", @"key4", nil];

      // 先对 key 进行排序,再遍历数组
      id keys1 = [dic keysSortedByValueUsingSelector:@selector(compare:)];

      for (id key in keys1) {
      NSLog(@"%@ = %@", key, dic[key]);
      }
    • Swift

      1
      2
      3
      4
      5
      6
      7
      let nsDic: NSDictionary = NSDictionary(dictionary: ["key1": "value1", "key2": "value2", "key3":"value3", "key4":"value4"])

      let keys2 = nsDic.keysSortedByValueUsingSelector(#selector(NSNumber.compare(_:)))

      for key in keys2 {
      print(nsDic.objectForKey(key))
      }
  • 用 Block(用闭)排序

    • Objective-C

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", 
      @"value3", @"key3", @"value4", @"key4", nil];

      id keys2 = [dic keysSortedByValueUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
      return [obj1 compare:obj2];
      }];

      for (id key in keys2) {
      NSLog(@"%@ = %@", key, dic[key]);
      }
    • Swift

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      let nsDic: NSDictionary = NSDictionary(dictionary: ["key1": "value1", "key2": "value2", "key3":"value3", "key4":"value4"])

      let keys1 = nsDic.keysSortedByValueUsingComparator { (obj1: AnyObject, obj2: AnyObject) -> NSComparisonResult in

      return (obj1 as! String).compare(obj2 as! String)
      }

      for key in keys1 {
      print(nsDic.objectForKey(key))
      }

13、Dictionary 与 NSDictionary 的相互转换

  • Dictionary 与 NSDictionary 之间可以直接相互转换。Dictionary 转转成 NSDictionary 时,数组中的各项元素被转换为 AnyObject 类型。NSDictionary 转换成 Dictionary 时,数组中的各项元素也被转换为 AnyObject 类型。

13.1 Dictionary 转 NSDictionary

  • Swift

    1
    2
    3
    4
    5
    6
    7
    let dictinoary: [String:String] = ["key1": "value1", "key2": "value"]

    // Dictionary 转换成 NSDictionary<AnyObject, AnyObject> 型
    let nsDictionary1: NSDictionary = dictinoary

    // Dictionary 转换成 NSDictionary<AnyObject, AnyObject> 型
    let nsDictionary2: NSDictionary = dictinoary as NSDictionary

13.2 NSDictionary 转 Dictionary

  • Swift

    1
    2
    3
    4
    5
    6
    7
    let dictinoary: [String:String] = ["key1": "value1", "key2": "value"]

    // NSDictionary 转换成 Dictionary<AnyObject, AnyObject> 型
    let swiftDictionary1: Dictionary = nsDictionary1 as Dictionary

    // NSDictionary 转换成 Dictionary<String, String> 型
    let swiftDictionary2: Dictionary = nsDictionary1 as! [String:String]
文章目录
  1. 1. 前言
  2. 2. 1、不可变字典的创建
  3. 3. 2、NSDictionary/Dictionary 字典中元素个数的计算
  4. 4. 3、NSDictionary/Dictionary 通过 key 找对应的 value
    1. 4.1. 3.1 NSDictionary 通过 key 找对应的 value
    2. 4.2. 3.2 Dictionary 通过 key 找对应的 value
  5. 5. 4、NSDictionary 通过 value 找对应的 key
  6. 6. 5、NSDictionary/Dictionary 字典中所有 key 的获取
    1. 6.1. 5.1 NSDictionary 字典中所有 key 的获取
    2. 6.2. 5.2 Dictionary 字典中所有 key 的获取
  7. 7. 6、NSDictionary/Dictionary 字典中所有 value 的获取
    1. 7.1. 6.1 NSDictionary 字典中所有 value 的获取
    2. 7.2. 6.2 Dictionary 字典中所有 value 的获取
  8. 8. 7、NSMutableDictionary/Dictionary 可变字典的创建
    1. 8.1. 7.1 NSMutableDictionary 可变字典的创建
    2. 8.2. 7.2 Dictionary 字典的创建
  9. 9. 8、NSMutableDictionary/Dictionary 字典中键值对的追加
    1. 9.1. 8.1 NSMutableDictionary 字典中键值对的追加
    2. 9.2. 8.2 Dictionary 字典中键值对的追加
  10. 10. 9、NSMutableDictionary/Dictionary 字典中元素的删除
    1. 10.1. 9.1 NSMutableDictionary 字典中元素的删除
    2. 10.2. 9.2 Dictionary 字典中元素的删除
  11. 11. 10、NSMutableDictionary/Dictionary 字典中元素的修改
    1. 11.1. 10.1 NSMutableDictionary 字典中元素的修改
    2. 11.2. 10.2 Dictionary 字典中元素的修改
  12. 12. 11、字典遍历
  13. 13. 12、字典排序
  14. 14. 13、Dictionary 与 NSDictionary 的相互转换
    1. 14.1. 13.1 Dictionary 转 NSDictionary
    2. 14.2. 13.2 NSDictionary 转 Dictionary
隐藏目录