不变集合 NSSet

 

//1.使用实例方法创建集合

        NSSet *set5 = [[NSSet alloc] initWithObjects:@"kgjlasd", @"popo", @"fss", nil];

        NSLog(@"%@", set5);

    NSSet *set6 = [NSSet setWithObjects:@"qwe"@"asd"@"zxc"nil];

    NSSet *set7 = [NSSet setWithObjects:@"qwe"@"asd"nil];

//判断两个集合是否有交集

    int a = [set7 intersectsSet:set6];

    NSLog(@"%d", a);

//判断两个集合是否相等

    int b = [set7 isEqualToSet:set6];

    NSLog(@"%d", b);

//判断当前集合是否是子集

    int c = [set7 isSubsetOfSet:set6];  

    NSLog(@"%d", c);

    

            

//2.实用类方法创建

        NSSet *set1 = [NSSet set];  //创建一个空的集合对象

        NSSet *set2 = [NSSet setWithObjects:@"qwe", @"asd", @"zxc", nil]; //添加多个字符串的

        NSLog(@"%@", set2);      

//创建数组

        NSArray *array = [NSArray arrayWithObjects:@"ada", @"664", @"p54dx", nil];

//使用数组创建集合

        NSSet *set3 = [NSSet setWithArray:array];

        NSLog(@"%@", set3);

//使用集合创建集合

        NSSet *set4 = [NSSet setWithSet:set2];

        NSLog(@"%@", set4);

 

 

//3.枚举访问集合

        NSEnumerator *aaaa = [set2 objectEnumerator];

        NSString *s = nil;

        while (s = [aaaa nextObject]) {

            NSLog(@"%@", s);
    

posted on 2014-04-28 16:11  Azazqiang  阅读(214)  评论(0编辑  收藏  举报

导航