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);
        
  • 相关阅读:
    git技能
    iOS 命名规则
    iOS crash 报错类型
    iOS 面试相关
    【转】app后端如何选择合适的数据库产品
    App的token机制
    【转】Spring注解详解
    spring mvc ModelAndView 404的原因
    ibatis 环境搭建(1)
    Android中的Selector的用法
  • 原文地址:https://www.cnblogs.com/Azazqing/p/3696587.html
Copyright © 2011-2022 走看看