the difference between Nsset and Nsarray
Nsset exactly what type, in fact it and nsarray functional nature, for storing objects, belong to the collection; Nsset, Nsmutableset class declares programming interface objects, unordered collections, which are stored in memory in a discontinuous way, unlike Nsarray, Nsdictionary (all ordered collections) class declares that the programming interface object is an ordered set, where the memory location is contiguous;
Nsset and our Common Nsarry difference is: In the search for an element nsset more efficient than nsarray, mainly because it uses an algorithm hash (hash, can also be translated as a hash); The development documentation explains this: you can use sets as an Alternative to arrays when the order of elements isn ' t important and performance in testing whether a object is contained The set is a consideration-while arrays was ordered, testing for membership was slower than with sets.
For example, if you want to store element A, a hash algorithm can directly find the location where a should be stored, and also, when you want to access a, a hash process can find the location of a storage. For Nsarray, if you want to know if a is not in the array, you need to facilitate the entire array, obviously less efficient;
Nsset,nsarray are classes, you can add only cocoa objects, and if you need to include basic data types (int,float,bool,double, etc.), you need to encapsulate the data into a nsnumber type.
Summary of common methods of Nsset
| + (ID) setwithobjects:obj1,obj2,... nil |
Create a new collection with a set of objects |
| -(ID) initwithobjects:obj1,obj2,.... nil |
Initializes a newly allocated collection with a set of objects |
| -(Nsuinteger) Count |
Returns the number of members of a collection |
| -(BOOL) containsobject:obj |
Determines whether the collection contains object obj |
| -(BOOL) member:obj |
Determines whether the collection contains object obj |
| -(nsenumerator*) Objectenumerator |
Returns all objects in the collection to an object of type Nsenumerator |
| -(BOOL) Issubsetofset:nsset |
Determines whether a collection is a subset of Nsset |
| -(BOOL) Intersectsset:nsset |
Determines whether the intersection of two sets has at least one element |
| -(BOOL) Isequaltoset:nsset |
Determines whether two sets are equal |
Summary of common methods of Nsmutableset
| -(ID) setwithcapcity:size |
To create a new collection with size sizes |
| -(ID) initwithcapcity:size |
Initializes a newly allocated collection of size |
| -(void) addobject:obj |
Add Object obj to the collection |
| -(void) removeobject:obj |
To delete an object from the collection obj |
| -(void) removeallobjects |
Delete all objects in the collection |
| -(void) Unionset:nsset |
Add all elements of Nsset to the collection |
| -(void) Minusset:nsset |
Remove all nsset elements from the collection |
| -(void) Interectset:nsset |
Set and Nsset do intersection operations |
The difference between Nsset and Nsarray