Directly on the code:
/ * * Nsset Immutable Collection * */ //Two types of initialization methodsNsset *set1 = [[Nsset alloc] initwithobjects:@"1", @"2", @"3",Nil] ;NSLog( @"%@", Set1); Nsset *set2 = [Nsset setwithobjects:@" A", @"All", @" the",Nil] ;NSLog( @"%@", Set2);//Using an array object to create a collection object Nsarray*array = @[@1, @2, @2] ;//initwitharray and Setwitharray convert the array object to a collection object, which filters out duplicate objects in the arrayNsset *set3 = [[Nsset alloc] initwitharray:array];NSLog( @"%@", Set3); Nsset *set4 = [Nsset Setwitharray:array];NSLog( @"%@", SET4);//Gets the number of objects in the collection NSLog( @"%ld", [Set4 Count]);//Gets the object in the collection (returns a single object that returns nil if there are no objects in the collection) IDObject1 = [Set4 anyobject];NSLog( @"%@", Object1);//Determines whether a given object is contained in the specified collection NSString*RESULT1 = [Set4 containsobject:@2] ? @"YES": @"NO";NSLog( @"%@ is contained int set%@", @2, RESULT1);///@2 to @ "2" Results printed NO//NSString *RESULT1 = [Set4 containsobject:@ "2"]? @ "YES": @ "NO";//NSLog (@ "%@ is contained int set%@" @ "2", RESULT1); / * * nsmutableset Variable set * */ //InitializeNsmutableset *mutableset1 = [[Nsmutableset alloc] init];NSLog( @"%@", MutableSet1); Nsmutableset *mutableset2 = [Nsmutableset set];NSLog( @"%@", MutableSet2);//created with immutable objectsNsmutableset *mutableset3 = [[Nsmutableset alloc] initwithset:set1];NSLog( @"%@", MutableSet3); Nsmutableset *mutableset4 = [Nsmutableset Setwithset:set1];NSLog( @"%@", MUTABLESET4);//Add collection elements (Note: @4 and @ "4" are not the same)[MutableSet4 addobject:@4] ;NSLog( @"%@", MUTABLESET4);//Delete a single collection element[MutableSet4 removeobject:@4] ;NSLog( @"%@", MUTABLESET4);//Delete all collection elements[MutableSet4 removeallobjects];NSLog( @"%@", MUTABLESET4);/* * nscountedset * * is a subclass of Nsset that can record the number of repetitions of elements in the collection */ //Nscountedset *countset1 = [Nscountedset set]; [CountSet1 addobject:@1] ; [CountSet1 addobject:@2] ; [CountSet1 addobject:@3] ; [CountSet1 addobject:@2] ;NSLog( @"%@", CountSet1);//Gets the number of times an object has occurred in the collection individually//NSLog (@ "%ld", [CountSet1 countofobjc:@3]); NSLog( @"%ld", [CountSet1 countforobject:@5] ) ;
Objective-c----Nsset, Nsmutableset, Nscountedset