zoukankan      html  css  js  c++  java
  • 不变集合 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);
        
  • 相关阅读:
    投票通过,PHP 8 确认引入 Union Types 2.0
    Laravel 菜鸟的晋级之路
    给公司写的composer包开发的规范
    Swoft 源码剖析
    听说PHP的生成器yield处理大量数据杠杠的
    读懂JWT的使用,你就会用PHP如何实现了
    python标准库及其它应用
    python常用算法题
    python迭代器实例
    python生成器实例
  • 原文地址:https://www.cnblogs.com/Azazqing/p/3696587.html
Copyright © 2011-2022 走看看