NSArray vs NSDictionary look up(NSArray vs NSDictionary 查找)
问题描述
检查一个对象是否已经存在于一个列表中更快更便宜.通过使用 NSArray contains 对象或检查 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 containsObject 选择器是否也遍历整个数组元素?另外检查一个键是否已经存在于字典中呢?这是否需要遍历所有键.
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 vs NSDictionary 查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:NSArray vs NSDictionary 查找
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01