NSArray与NSDictionary查找 [英] NSArray vs NSDictionary look up

查看:159
本文介绍了NSArray与NSDictionary查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查列表中是否存在对象更快,更便宜。通过使用NSArray包含对象或通过检查一个键是否已经存在一个NSDictionary?

Which is quicker and less expensive for checking if an object already exists within a list. By using the NSArray contains object or by checking if a key already exists for an NSDictionary?

NSArray包含对象选择器是否遍历整个数组元素?还有检查一个字典中是否已经存在一个键?这需要遍历所有的键。

Also does the NSArray containObject selecter iterate through the whole array elements? Also what about checking if a key already exists within a dictionary? Does that require iterating through all the keys.

最后,什么是最好的和最快的方法来检查一个对象是否已经存在于一个大的对象列表类)。

Finally, what is the best and quickest way to check if an object already exists within a large list of objects (of the same class).

提前感谢

推荐答案

你在说什么?速度的差异可能是不相关的,因此使得选择是在代码中最有意义的选择。事实上,这应该是第一优先,除非,直到你知道有一个速度问题。

How many values are you talking about? The difference in speed may be irrelevant, thus making the choice be the one that makes the most sense in the code. In fact, that should probably be the first priority, unless and until you know that there is a speed problem.

短版本:使用NSDictionary除非你有特定的需要到。

Short version: Use NSDictionary unless you have a specific need not to.

这篇关于NSArray与NSDictionary查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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