代码改变世界

NSMutableSte 可变集合 继承Set

2015-12-20 19:36  AB小博客  阅读(145)  评论(0)    收藏  举报
//
//  main.m

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //不能重复 无序  继承NSSet
        NSMutableSet *mset = [NSMutableSet setWithCapacity:10];
        [mset addObject:@"one"];
         [mset addObject:@"two"];
         [mset addObject:@"one"];
         [mset addObject:@"two"];
        NSMutableSet *set1= [NSMutableSet setWithObjects:@"a",@"b",@"c",@"d", @"two",nil];
        NSLog(@"%@",mset);
        
       // [mset removeObject:@"one"];
             NSLog(@"%@",mset);
        
      NSLog(@"%ld",mset.count);
        
        NSEnumerator *e = [mset objectEnumerator];
        NSString *s;
        while ((s=[e nextObject])!=0) {
            NSLog(@"%@",s);
        }
        NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];
        [mset addObjectsFromArray:array];
        NSLog(@"%@",mset);
        [mset removeAllObjects];
        //交集
        [mset intersectSet:set1];
        NSLog(@"%@",mset);
        //求两个集合的并集
        [mset unionSet:set1];
       NSLog(@"111%@",mset);
       //差集
        [mset minusSet:set1];
        NSLog(@"111%@",mset);
        
 }
    return 0;
}