当它更好了一个NSArray使用一个的NSSet? [英] When is it better to use an NSSet over an NSArray?

查看:100
本文介绍了当它更好了一个NSArray使用一个的NSSet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用NSSets多次在我的应用程序,但从来没有建立一个自己。

I have used NSSets many times in my apps, but have never created one myself.

我的问题是:

当是它更好地使用<一个href=\"https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSSet_Class/\"><$c$c>NSSet相对于一<一href=\"https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/doc/c_ref/NSArray\"><$c$c>NSArray为什么?

When is it better to use a NSSet as opposed to a NSArray and why?

推荐答案

在集合中的项目的顺序并不重要,台提供集合中寻找项目更好的性能。

When the order of the items in the collection is not important, sets offer better performance for finding items in the collection.

的原因是,一组使用散列值来找到的物品(如字典),而一个阵列具有遍历其全部内容以找到一个特定的对象

The reason is that a set uses hash values to find items (like a dictionary) while an array has to iterate over its entire contents to find a particular object.

这篇关于当它更好了一个NSArray使用一个的NSSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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