**
三者的异同
一篇三者特点对比
一篇三种集合遍历效率比较的文章
NSHipster上有一篇文章解释了 可变/不可变类簇的缺点
简单总结:
1. 三者都是集合,只能存放对象类型,对于C语言基础数据类型(int, float, double, BOOL等),则需要封装成NSNumber类型,在保存到集合类中
2. 三者都可以混合存放不同的对象类型(NSString、NSData等等)
3. NSArray存放的是有序的对象
An NSArray can hold objects in a sorted order. So object1 is always object1, and object2 is always object2. You can retrieve the first and last object from the array.
NSSet跟NSArray很像,但它存放的是无序的
You would typically use a set when access speed is of the essence and order doesn’t matter, or is determined by other means (through a predicate or sort descriptor). Core Data for example uses sets when managed objects are accessed via a to-many relationship.
NSDictionary 也是无序的,但是它已key-value的方式存储,检索会很快
The NSDictionary class is a bit of a magical one: it stores objects as key value pairs. Objects are not ordered, but can be retrieved simply by addressing them with an arbitrary string value.
4.NSSet的强大之处在于,可以方便的进行集合的操作(求交集、并集、差集等),如:intersectSet:,minusSet:和unionSet: