NSDictionary 初始化

NSDictionary *dic1=[NSDictionary dictionaryWithObject:@"1" forKey:@"a"];
       NSLog(@"%@",dic1);
       /*结果:
        {
        a = 1;
        } */
       
       //常用的方式
       NSDictionary *dic2=[NSDictionary dictionaryWithObjectsAndKeys:
                       @"1",@"a", @"2",@"b", @"3",@"c", nil];
                           
       NSLog(@"%@",dic2);
       /*结果:
       {
        a = 1;
        b = 2;
        c = 3; }
       */
       
       NSDictionary *dic3=[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1",@"2", nil] forKeys:[NSArray arrayWithObjects:@"a",@"b", nil]];
       NSLog(@"%@",dic3);
       /*结果:
       {
        a = 1;
        b = 2;
        }
       */
       
       //更简单的方式
       NSDictionary *dic4=@{@"1":@"a",@"2":@"b",@"3":@"c"};
       NSLog(@"%@",dic4);
       /*结果:
        {
        1 = a;
        2 = b;
        3 = c; }
        */
 
原文地址:https://www.cnblogs.com/kluan/p/4819410.html