#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])

{

@autoreleasepool {

NSSet *set1 = [NSSet setWithObjects:@"a", @"b", @"c", @"d", nil];

NSSet *set2 = [[NSSet alloc] initWithObjects:@"1", @"2", @"3", nil];

NSArray *array = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];

NSSet *set3 = [NSSet setWithArray:array];

NSLog(@"set1 :%@", set1);

NSLog(@"set2 :%@", set2);

NSLog(@"set3 :%@", set3);

//获取集合个数

NSLog(@"set1 count :%d", set1.count);

//以数组的形式获取集合中的所有对象

NSArray *allObj = [set2 allObjects];

NSLog(@"allObj :%@", allObj);

//获取任意一对象

NSLog(@"anyObj :%@", [set3 anyObject]);

//是否包含某个对象

NSLog(@"contains :%d", [set3 containsObject:@"obj2"]);

//是否包含指定set中的对象

NSLog(@"intersect obj :%d", [set1 intersectsSet:set3]);

//是否完全匹配

NSLog(@"isEqual :%d", [set2 isEqualToSet:set3]);

//是否是子集合

NSLog(@"isSubSet :%d", [set3 isSubsetOfSet:set1]);

NSSet *set4 = [NSSet setWithObjects:@"a", @"b", nil];

NSArray *ary = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];

NSSet *set5 = [set4 setByAddingObjectsFromArray:ary];

NSLog(@"addFromArray :%@", set5);

NSMutableSet *mutableSet1 = [NSMutableSet setWithObjects:@"1", @"2", @"3", nil];

NSMutableSet *mutableSet2 = [NSMutableSet setWithObjects:@"a", @"2", @"b", nil];

NSMutableSet *mutableSet3 = [NSMutableSet setWithObjects:@"1", @"c", @"b", nil];

//集合元素相减

[mutableSet1 minusSet:mutableSet2];

NSLog(@"minus :%@", mutableSet1);

//只留下相等元素

[mutableSet1 intersectSet:mutableSet3];

NSLog(@"intersect :%@", mutableSet1);

//合并集合

[mutableSet2 unionSet:mutableSet3];

NSLog(@"union :%@", mutableSet2);

//删除指定元素

[mutableSet2 removeObject:@"a"];

NSLog(@"removeObj :%@", mutableSet2);

//删除所有数据

[mutableSet2 removeAllObjects];

NSLog(@"removeAll :%@", mutableSet2);

}

return 0;

}

Objective-C:NSSet和NSMutbaleSet的用法的更多相关文章

  1. NSSet、NSMutableSet基本用法

    NSSet.NSMutableSet基本用法 在Foundation框架中,提供了NSSet类,它是一组单值对象的集合,且NSSet实例中元素是无序,同一个对象只能保存一个. 一.不可变集合NSSet ...

  2. Objective-C Foundation框架

    1.字符串 OC由两个字符串:NSString和NSMutableString,NSString代表字符序列不可变的字符串,而NSMutableString则代表字符序列可变的字符串. 1.1 创建字 ...

  3. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  4. 用法总结:NSArray,NSSet,NSDictionary

    用法总结:NSArray,NSSet,NSDictionary Foundation framework中用于收集cocoa对象(NSObject对象)的三种集合分别是: NSArray 用于对象有序 ...

  5. 用法总结:NSArray,NSSet,NSDictionary-备用

    Foundation framework中用于收集cocoa对象(NSObject对象)的三种集合分别是: NSArray 用于对象有序集合(数组)NSSet 用于对象无序集合      (集合)NS ...

  6. NSArray,NSMutable和NSSet,NSMutableSet和NSDictionary,NSMutableDictionary用法

    开始编写应用程序的代码时,可以利用大量的 Objective-C 框架.其中,为所有应用程序提供基本服务的 Foundation 框架尤为重要.Foundation 框架包括表示基本数据类型的值类(如 ...

  7. NSSet 用法

    //集合NSSet //集合也是储存对象,和字典一样也是无序存储 //集合中里面的元素不能重复 //集合里面的元素可以随机取出 //用数组放到集合中 NSArray *a10 = @[p1 , p2 ...

  8. Objective C (iOS) for Qt C++ Developers(iOS开发,Qt开发人员需要了解什么?)

    Qt/C++开发人员眼中的Obj-C      对于我们第一次自己定义iOS应用来说,对于来自Qt/C++开发人员来说,我不得不学习Objective-C相关语法与知识 为了让读者可以更easy理解这 ...

  9. iOS多线程之8.NSOPeration的其他用法

      本文主要对NSOPeration的一些重点属性和方法做出介绍,以便大家可以更好的使用NSOPeration. 1.添加依赖 - (void)addDependency:(NSOperation * ...

随机推荐

  1. [bzoj4766]文艺计算姬——完全二分图生成树个数

    Brief Description 求\(K_{n,m}\) Algorithm Design 首先我们有(Matrix Tree)定理,可以暴力生成几组答案,发现一些规律: \[K_{n,m} = ...

  2. CVE-2017-5521: Bypassing Authentication on NETGEAR Routers(Netgear认证绕过漏洞)

    SpiderLabs昨天发布的漏洞, 用户访问路由器的web控制界面尝试身份验证,然后又取消身份验证,用户就会被重定向到一个页面暴露密码恢复的token.然后通过passwordrecovered.c ...

  3. HDU1142 (Dijkstra+记忆化搜索)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. VC++/MFC中调用CHM帮助文档的方法

    转载:http://blog.csdn.net/hediping9811/article/details/23341387 (1)用Word编辑好帮助文档,并保存为网页格式,如mhtml格式. (2) ...

  5. try_module_get和module_put【转】

    转自:http://blog.csdn.net/adaptiver/article/details/7000617 转自:http://apps.hi.baidu.com/share/detail/4 ...

  6. PL/SQL 01 代码编写规则

    1.标识符命名规则当在 PL/SQL 中使用标识符定义变量.常量时,标识符名称必须以字符开始,并且长度不能超过 30 个字符.另外,为了提高程序的可读性,Oracle 建议用户按照以下规则定义各种标识 ...

  7. Mac-sublime text 3破解版

    在史蒂芬周下载破解版 安装package control import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f ...

  8. solr params.json

    The Request Parameters API allows creating parameter sets that can override or take the place of par ...

  9. (三)mysql数据库基本操作

    (1)SQL语句:结构化查询语句 DDL语句 数据定义语言:数据库丶表丶视图丶索引丶存储过程丶函数丶create drop alter DML语句 数据库操作语言:插入数据insert,删除数据del ...

  10. [jquery] ajax parsererror

    http://stackoverflow.com/questions/5061310/jquery-returning-parsererror-for-ajax-request 方法一: 直接去掉 d ...