Object -C NSSet -- 笔记
//
// main.m
// NSSET
//
// Created by facial on 25/8/15.
// Copyright (c) 2015 facial_huo. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSSet *set = [[NSSet alloc] initWithObjects:@"one", @"two", @"three", @"four", nil];
//打印set 获取nsset的长度
NSLog(@"%@, %lu", set, [set count] );
bool ret = [set containsObject: @"one"];
NSLog(@"%d", ret);
//判断两个集合是否相等
NSSet *set2 = [[NSSet alloc] initWithObjects: @"one", @"two", @"three", @"four", @"five",nil];
bool isSame = [ set isEqualToSet: set2];
NSLog(@"%d", isSame);
//判断是否是子集合
bool isSub = [set isSubsetOfSet: set2];
NSLog(@"%d", isSub);
//枚举器 遍历nsset元素
NSEnumerator *enumor = [set objectEnumerator];
NSString *item;
while (item = [enumor nextObject]) {
NSLog(@"%@",item);
}
//通过数组创建集合
NSArray *array = [[NSArray alloc] initWithObjects: @"arry1", @"arry2", @"arry3", nil];
NSSet *arraySet = [[NSSet alloc] initWithArray:array ];
NSLog(@"%@", arraySet);
//把集合变成数组
NSArray *SetToArray = [arraySet allObjects];
NSLog(@"%@", SetToArray);
// NSMutableSet; 添加元素
NSMutableSet *mSet = [NSMutableSet new];
[mSet addObject: @"a"];
[mSet addObject: @"b"];
[mSet addObject: @"c"];
NSLog(@"%@", mSet);
//删除元素
[mSet removeObject: @"a"];
NSLog(@"%@", mSet);
// 把一个集合添加到另外一个集合
NSSet *test_set = [[NSSet alloc] initWithObjects: @"d", @"e", @"f", nil];
[mSet unionSet: test_set];
NSLog(@"%@", mSet);
//取两个集合的交集
NSSet *test_set2 = [[NSSet alloc] initWithObjects: @"a", @"b", @"f", nil];
[mSet minusSet: test_set2];
NSLog(@"%@", mSet);
//索引集合
NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange: NSMakeRange(2, 3)];
NSArray *array2 = [[NSArray alloc] initWithObjects: @"a", @"b", @"c",@"d", @"e", nil];
NSArray *newArray2 = [array2 objectsAtIndexes: indexSet];
NSLog(@"%@", newArray2);
//
NSMutableIndexSet *muteIndex = [[NSMutableIndexSet alloc] init];
[muteIndex addIndex: 0];
[muteIndex addIndex: 1];
NSArray *newArray3 = [[NSArray alloc] initWithObjects: @"aa", @"bb", @"cc", @"dd", @"ee", nil];
NSArray *newArray4 = [newArray3 objectsAtIndexes: muteIndex];
//NSArray *a = [array2 objectAtIndex: index];
NSLog(@"%@", newArray4);
}
return 0;
}
Object -C NSSet -- 笔记的更多相关文章
- Object C学习笔记24-关键字总结
学习Object C也有段时间了,学习的过程中涉及到了很多Object C中的关键字,本文总结一下所涉及到的关键字以及基本语法. 1. #import #import <> 从syste ...
- Object C学习笔记22-#define 用法
上一篇讲到了typedef 关键字的使用,可以参考文章 Object C 学习笔记--typedef用法 .而在c中还有另外一个很重要的关键字#define. 一. #define 简介 在C中利用预 ...
- Object C学习笔记21-typedef用法
在上一章的学习过程中遇到了一个关键字typedef,这个关键字是C语言中的关键字,因为Object C是C的扩展同样也是支持typedef的. 一. 基本作用 typedef是C中的关键字,它的主要作 ...
- Object C学习笔记18-SEL,@ selector,Class,@class
本章是对上一章<<Object C学习笔记17-动态判断和选择器>>的一点补充,所以比较简单点. 一. SEL 类型 在上一篇介绍了几个方法,都只是介绍了其使用方式但是没有具体 ...
- Object C学习笔记17-动态判断和选择器
当时学习Object C的时被人鄙视了一顿,说使用.NET的思想来学Object C就是狗屎:不过也挺感谢这位仁兄的,这让我学习的时候更加的谨慎.今天的学习笔记主要记录Object C中的动态类型相关 ...
- Object C学习笔记10-静态方法和静态属性
在.NET中我们静态使用的关键字static有着举足轻重的作用,static 方法可以不用实例化类实例就可以直接调用,static 属性也是如此.在Object C中也存在static关键字,今天的学 ...
- Object C学习笔记24-关键字总结(转)
学习Object C也有段时间了,学习的过程中涉及到了很多Object C中的关键字,本文总结一下所涉及到的关键字以及基本语法. 1. #import #import <> 从syste ...
- Object C学习笔记15-协议(protocol)
在.NET中有接口的概念,接口主要用于定义规范,定义一个接口关键字使用interface.而在Object C 中@interface是用于定义一个类的,这个和.NET中有点差别.在Object C中 ...
- Object C学习笔记13-Dictionary字典
通过Array数组和Set集合的学习和理解,可以想象得到Dictionary也分为两种情况了,那就是可变和不可变两种类型的.的确如此,在Object C中提供了两个字典类,分别为NSDictionar ...
随机推荐
- 关于Core Data的一些整理(二)
关于Core Data的一些整理(二) 创建NSManagedObject的子类时,有一点是在这中间要强调的一点是,要不要勾选 Use scalar properties for primitive ...
- UICollectionView出现the behavior of the UICollectionViewFlowLayout is not defined because:
2015-01-28 21:55:17.790 Demo[636:9351] the behavior of the UICollectionViewFlowLayout is notdefined ...
- linux关机重启命令浅析
linux关机重启命令 今天我们来介绍下linux系统中常用到的关机重启命令—shutdown.halt.reboot.poweroff以及init. shutdown命令 以安全的方式关闭系统或重启 ...
- 08_linux下安装chrome
首先下载chrome,需要改hosts哦(o(^▽^)o,别告诉我你不会,可以问度娘.谷哥哦) 下载地址:https://dl.google.com/linux/direct/google-chrom ...
- LIKE匹配关键字
1.% 匹配任意数目字符(包括零个字符) SELECT * FROM edo_user WHERE true_name LIKE '王%' 应用:关键字查询 WHERE u.true_name lik ...
- 直接插入排序(Straight Insertion Sort)的C语言实现
原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia 直接插入排序(Straight Insertion Sort)的基本思想是将新记录插入到 ...
- ZOJ1074 (最大和子矩阵 DP)
F - 最大子矩阵和 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Descri ...
- Android 数据库读取数据显示 [5]
2016-12-1 课程内容 昨天学了Android数据库升级.降级.创建 今天把数据库表里面的数据读取出来显示到手机屏幕上 下面代码是MainActivity.java 的代码 package co ...
- ubuntu matplotlib 安装
sudo apt-get install python-numpy //必须 sudo apt-get install python-matplotlib //必须
- 【技术贴】xp下改变7zip默认关联图标和美化教程
今天发现7z被还原成了复古样式,就是那种win2000的图标,感觉果然是技术人员做的美工. 于是开始想办法替换掉,自己找到了一个最简单的办法 首先,默认用7z打开 1.随便找到一个7z后缀,然后右键, ...