#import <Foundation/Foundation.h>
- int main (int argc, const char * argv[])
- {
- @autoreleasepool {
- Nsset *set1 = [Nsset setwithobjects:@ "a", @ "B", @ "C", @ "D", nil];
- Nsset *set2 = [[Nsset alloc] initwithobjects:@ "1", @ "2", @ "3", nil];
- Nsarray *array = [Nsarray arraywithobjects:@ "a", @ "B", @ "C", nil];
- Nsset *set3 = [Nsset Setwitharray:array];
- NSLog (@ "Set1:%@", Set1);
- NSLog (@ "Set2:%@", Set2);
- NSLog (@ "Set3:%@", Set3);
- Get the number of collections
- NSLog (@ "Set1 count:%d", set1.count);
- Gets all the objects in the collection as an array
- Nsarray *allobj = [Set2 allobjects];
- NSLog (@ "AllObj:%@", allobj);
- Get an arbitrary object
- NSLog (@ "Anyobj:%@", [Set3 Anyobject]);
- Whether to include an object
- NSLog (@ "contains:%d", [Set3 containsobject:@ "Obj2"]);
- Whether to include objects in the specified set
- NSLog (@ "intersect obj:%d", [Set1 Intersectsset:set3]);
- is exactly matched
- NSLog (@ "IsEqual:%d", [Set2 Isequaltoset:set3]);
- Whether it is a child collection
- NSLog (@ "Issubset:%d", [Set3 Issubsetofset:set1]);
- Nsset *set4 = [Nsset setwithobjects:@ "a", @ "B", nil];
- Nsarray *ary = [Nsarray arraywithobjects:@ "1", @ "2", @ "3", @ "4", nil];
- Nsset *set5 = [Set4 setbyaddingobjectsfromarray:ary];
- NSLog (@ "Addfromarray:%@", SET5);
- Nsmutableset *mutableset1 = [Nsmutableset setwithobjects:@ "1", @ "2", @ "3", nil];
- Nsmutableset *mutableset2 = [Nsmutableset setwithobjects:@ "a", @ "2", @ "B", nil];
- Nsmutableset *mutableset3 = [Nsmutableset setwithobjects:@ "1", @ "C", @ "B", nil];
- Subtract from collection element
- [MutableSet1 Minusset:mutableset2];
- NSLog (@ "Minus:%@", MutableSet1);
- Leaving only the equal elements
- [MutableSet1 Intersectset:mutableset3];
- NSLog (@ "intersect:%@", MutableSet1);
- Merging collections
- [MutableSet2 Unionset:mutableset3];
- NSLog (@ "union:%@", MutableSet2);
- Delete the specified element
- [MutableSet2 removeobject:@ "a"];
- NSLog (@ "Removeobj:%@", MutableSet2);
- Delete all data
- [MutableSet2 removeallobjects];
- NSLog (@ "RemoveAll:%@", MutableSet2);
- }
- return 0;
- }
The use of Objective-c:nsset and Nsmutbaleset