NSSet集合对象
来源:互联网 发布:诺德软件 编辑:程序博客网 时间:2024/04/19 23:40
//NSSet集合对象
//NSSet在存储对象时不是连续存储的,也不是顺序存储的
//NSSet使用散列表(hash table)的技术存储对象的,便于对对象查找对象可以一次命中
NSArray *array = [NSArrayarrayWithObjects:@1,@2,@3,nil];
NSSet *set = [NSSetsetWithObjects:@1,@3,nil];
NSSet *set2 = [NSSetsetWithArray:array];
[array enumerateObjectsUsingBlock:^(id _Nonnull obj,NSUInteger idx,BOOL *_Nonnull stop) {
NSLog(@"idx = %lu,obj = %@",idx,obj);
}];
[set enumerateObjectsUsingBlock:^(id _Nonnull obj,BOOL *_Nonnull stop) {
NSLog(@"obj = %@",obj);
}];
//NSMutableSet可变的集合对象
//NSSet中不能存储重复的对象
NSMutableSet *set3 = [[NSMutableSetalloc]init];
[set3 addObject:@1];
[set3 addObject:@2];
[set3 addObject:@3];
//[set3 removeObject:@2];
[set3 enumerateObjectsUsingBlock:^(id _Nonnull obj,BOOL *_Nonnull stop) {
NSLog(@"obj = %@",obj);
}];
//可以判断一个对象在集合中
if ([set3 containsObject:@2]) {
NSLog(@"2在set3里面");
}
id obj4 = [set3member:@2];
NSLog(@"%@",obj4);
//集合之间可以做集合运算
//1、将集合中两个相同的元素去掉
[set3 minusSet:set];
NSLog(@"%@",set3);
//2、求集合的并集
[set3 unionSet: set];
NSLog(@"%@",set3);
//3、求两个集合的交集
[set3 intersectSet:set];
NSLog(@"%@",set3);
//判断一个集合是否包含另一个集合
if ([set3isSubsetOfSet:set]) {
NSLog(@"set is subset of set3");
}
//NSSet在存储对象时不是连续存储的,也不是顺序存储的
//NSSet使用散列表(hash table)的技术存储对象的,便于对对象查找对象可以一次命中
NSArray *array = [NSArrayarrayWithObjects:@1,@2,@3,nil];
NSSet *set = [NSSetsetWithObjects:@1,@3,nil];
NSSet *set2 = [NSSetsetWithArray:array];
[array enumerateObjectsUsingBlock:^(id _Nonnull obj,NSUInteger idx,BOOL *_Nonnull stop) {
NSLog(@"idx = %lu,obj = %@",idx,obj);
}];
[set enumerateObjectsUsingBlock:^(id _Nonnull obj,BOOL *_Nonnull stop) {
NSLog(@"obj = %@",obj);
}];
//NSMutableSet可变的集合对象
//NSSet中不能存储重复的对象
NSMutableSet *set3 = [[NSMutableSetalloc]init];
[set3 addObject:@1];
[set3 addObject:@2];
[set3 addObject:@3];
//[set3 removeObject:@2];
[set3 enumerateObjectsUsingBlock:^(id _Nonnull obj,BOOL *_Nonnull stop) {
NSLog(@"obj = %@",obj);
}];
//可以判断一个对象在集合中
if ([set3 containsObject:@2]) {
NSLog(@"2在set3里面");
}
id obj4 = [set3member:@2];
NSLog(@"%@",obj4);
//集合之间可以做集合运算
//1、将集合中两个相同的元素去掉
[set3 minusSet:set];
NSLog(@"%@",set3);
//2、求集合的并集
[set3 unionSet: set];
NSLog(@"%@",set3);
//3、求两个集合的交集
[set3 intersectSet:set];
NSLog(@"%@",set3);
//判断一个集合是否包含另一个集合
if ([set3isSubsetOfSet:set]) {
NSLog(@"set is subset of set3");
}
0 0
- NSSet 集合对象
- NSSet 集合对象
- 集合对象-》NSSet
- NSSet集合对象
- Objective-c 集合对象 (NSSet 和 NSMutableSet)
- NSSet集合
- NSSet 集合
- 集合NSSet*
- iOS/Objective-C集合对象NSSet的使用
- OC-集合对象NSSet基本使用和方法介绍
- NSDictionary 字典 集合NSSet
- 集合与数组NSSet
- 整理NSSet集合
- Foundation -- OC集合 --NSSet
- OC基础-NSSet集合
- 【集合】NSSet相关
- Swift学习 集合(NSSet)
- 不可变集合NSSet
- JAVA设计模式(04):创建型-建造模式(Builder)
- 【饥荒mod制作吧第五篇】MOD下载及安装
- Android利用tcpdump和wireshark抓取网络数据包
- Linux下python升级至2.7步骤
- LUA学习(五) 迭代器
- NSSet集合对象
- git的使用
- HTTP返回状态码
- java字符串处理总结
- 密码学---PlayFair
- 指针才是C的精髓
- POJ 3164 Command Network【最小树形图】
- oc开发笔记4 ios 声像图 波形和频谱
- 关于手机天气应用中的城市搜索的联想查找方式优化