检查一个对象是否已经存在于一个列表中更快更便宜.通过使用 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 查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!