像输入一样订购 NSMutableDictionary 的输出 [英] Order the Output of NSMutableDictionary like the Input

查看:42
本文介绍了像输入一样订购 NSMutableDictionary 的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何按照输入的顺序输出字典的值.

how is it possbile to output the values of a dictionary in the order of input.

示例:

我的输入:

    [dicValue0 setObject:@"Start Date & Time" forKey:@"START_DATETIME"];
    [dicValue0 setObject:@"Specify End" forKey:@"SPECIFY_END"];
    [dicValue0 setObject:@"End Date & Time" forKey:@"END_DATETIME"];
    [dicValue0 setObject:@"Open End" forKey:@"END_OPEN"];

输出:

  • 开始日期和时间
  • 结束日期和时间
  • 指定结束
  • 开放式

我知道字典的工作原理,但我希望输出与输入的顺序相同!

I know how a dictionary works, but I want the output in the same order as the input!

我可以编写一个循环,按照输入的顺序对输出进行排序.但是,如果我有 10000+ 个值,那不是最好和性能最好的方法.苹果有什么东西可以帮助我解决这个问题吗?

I can write a loop which sorts me the output in the order of the input. But if i had 10000+ values that's not the best and performant way. Is there anything from apple, that helps me with this problem?

推荐答案

我很确定字典不会跟踪输入顺序.你是如何输出字典、遍历键或只是打印字典?

I am pretty sure that dictionaries are not keeping track of the input order. How are you outputting the dictionary, looping through keys or just printing the dictionary?

如果您知道要检索对象的顺序,则可以创建自己版本的键数组并循环遍历以按所需顺序从字典中提取对象

If you know the order you want to retrieve the objects, you can create your own version of the keys array and loop through that to pull out the objects from the dictionary in your desired order

这篇关于像输入一样订购 NSMutableDictionary 的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆