1, the use of Nsset
[Nsset setwithset: (Nsset *) set]; Constructs [Nsset setwitharray: (Nsarray *) array] with another set object, constructs [Nsset setwithobjects: ...] with an array, creates a collection object, and initializes the values in the collection, with the nil flag required at the end. [Set Count]; Get the length of this binding object. [Set Containsobject: ...]: Determines whether an incoming object exists in this collection and returns a bool value. [Set Objectenumerator]: puts the collection into the iterator. [Enumerator Nextobject]: Gets the next node data in the iterator, using the while traversal of the iterator to traverse the objects in the collection object. [Set Isequaltoset:objset]: Determines whether two sets are exactly equal and returns a bool value. [Set Issubsetofset:objset]: Determines whether all data in the collection is equal to the Objeset collection, and returns the bool value. [Set allobjects];
Nsset *Set= [Nsset setwithobjects:@" -",@" Age",@"Zhang San",@"name",@"male", nil]; Nsset*set1 = [Nsset setwithobjects:@" -",@" Age",@"Zhang San",@"name",@"male",@"Sex", nil]; NSLog (@"Set Count:%lu", [SetCount]); //determine if an age string is included if([SetContainsobject:@" Age"]) {NSLog (@"set contains age"); } //determine if set equals Set1 if([SetIsequaltoset:set1]) {NSLog (@"set equals Set1"); } //determines whether a set is a subset of Set1 if([SetIssubsetofset:set1]) {NSLog (@"Set Issubsetofset Set1"); } //get all Set objectsNsarray *array = [SetAllObjects]; NSLog (@"array:%@", array); //Iterative TraversalNsenumerator *enumerator = [SetObjectenumerator]; for(NSObject *Object inchenumerator) {NSLog (@"objects in Set1:%@",Object); }
2, the use of Nsmutableset
Nsmutableset inherits Nsset, which can use the Nsset method.
[Nsmutableset Setwithcapacity:6]: Creates a Mutable collection object, and the initialization length is 6.
[Set Addobject:obj]: Adds an object dynamically to the collection.
[Set Removeobject:obj]: Deletes an object from the collection.
[Set removeallobjects]: Deletes all objects in the collection.
[Set Unionset:obj]: Adds all the data of an obj collection to the collection.
[Set Minusset:obj]: Removes all data from an obj collection to the collection.
[Set Intersectset]: Removes all data from the collection that does not contain the Obj collection.
Nsmutableset *muset = [Nsmutableset setwithcapacity:6]; [Muset AddObject:@"Object 1"]; Nsset*Set= [Nsset setwithobjects:@"Object 2",@"Object 3",@"bitten by a penguin.", nil]; //adding set Data[Muset Unionset:Set]; for(NSObject *Object inchMuset) {NSLog (@"All nuset:%@",Object); } Nsset*set1 = [Nsset setwithobjects:@"Object 2",@"Object 3", nil]; //Delete total data containing Set1 in Muset[Muset Minusset:set1]; for(NSObject *Object inchMuset) {NSLog (@"After minusset:%@",Object);
This kind of use less, but still want to understand next!
Nsset and nsmutableset-by Wu Shulei