zoukankan      html  css  js  c++  java
  • NSDictionary 的有序性 (by the key in some rule)

    NSDictionary 的有序性: (by the key in some rule)

    NSDictionary*myDictionary =[NSDictionary dictionaryWithObjectsAndKeys:@"o1",@"k1",@"o6",@"k4",@"o2",@"k2",@"o3",@"k3",@"o5",@"k5", nil];NSInteger count =[myDictionary count];

    如下代码1:

      NSLog(@"%@ ", [myDictionary allKeys]);

        NSLog(@"%@ ", [myDictionary allValues]);

        

    每次运行都是这样的结果

    2014-04-10 10:55:58.548[3105:70b] (

        k4,

        k3,

        k2,

        k5,

        k1

    2014-04-10 10:55:58.548[3105:70b] (

        o6,

        o3,

        o2,

        o5,

        o1

    )

    修改k4 --> k6 

    每次运行结果为

    2014-04-10 10:53:38.318[3083:70b] (

        k3,

        k6,

        k2,

        k5,

        k1

    2014-04-10 10:53:38.318[3083:70b] (

        o3,

        o6,

        o2,

        o5,

        o1

     

        

    如下代码2:

        id __unsafe_unretained objects[count];

        id  __unsafe_unretained keys[count];

        [myDictionary getObjects:objects andKeys:keys];

        

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

            id obj = objects[i];

            id key = keys[i];NSLog(@"%@ -> %@", obj, key);

        }

    每次运行都是这样的结果

    o6 -> k4

    o3 -> k3

    o2 -> k2

    o5 -> k5

    o1 -> k1

    修改k4 --> k6 

    每次运行结果为

    o3 -> k3

    o6 -> k6

    o2 -> k2

    o5 -> k5

    o1 -> k1

    由此可知

    NSDictionary  其实是有序的: (by the key in some rule) 根据key进行排序

  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业02
    C语言II博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
    学期总结
    C语言I博客作业08
  • 原文地址:https://www.cnblogs.com/zander/p/3655891.html
Copyright © 2011-2022 走看看