NSArray vs NSDictionary 查找

2024-08-12移动开发问题
23

本文介绍了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 查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21