Nsarray ordered Natural order
Nsset disorderly.
Nsset cannot store duplicate data, it can be used to remove duplicate data
1. Create a Collection
1.1 Creating immutable Collections
1 NSSet * set = [[NSSet alloc] initWithObjects:@"one",@"two",@"three", nil];
2 NSLog(@"%@",set);
3
4 NSSet * set1 = [[NSSet alloc] initWithObjects:@"one",@"two",@"one",@"three", nil];
5 NSLog(@"%@",set1);
1.2 Creating a Mutable collection
1 NSMutableSet * muset = [[NSMutableSet alloc] initWithObjects:@"one",@"two", nil];
2
3 NSLog(@"%@",muset);
2. Get the number of elements
1 nsuinteger count = [Set1 count]; 2 NSLog (@ "%lu", count);
3. Determine if the object is included
1 BOOL isContain = [set1 containsObject: @ "T"];
2 if (isContain) {
3 NSLog (@ "include");
4} else {
5 NSLog (@ "excluding");
6}
-(BOOL) Containsobject: (ObjectType) AnObject;
4. Array conversion to Collection
1 NSArray * arr = @[@"one",@"two",@"three",@"one"];
2 NSSet * set2 =[NSSet setWithArray:arr];
3 NSLog(@"set2 %@",set2);
5. Variable array additions and deletions
5.1 Add
1 [muset addobject:@ "three"]; 2 NSLog (@ "%@", muset);
5.2 Delete
1 [muset removeobject:@ "one"]; 2 NSLog (@ "%@", muset);
Delete all
1 [Muset removeallobjects]; 2 NSLog (@ "%@", muset);
A preliminary knowledge of objective-c collection