//

//  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 -- 笔记的更多相关文章

  1. Object C学习笔记24-关键字总结

    学习Object C也有段时间了,学习的过程中涉及到了很多Object C中的关键字,本文总结一下所涉及到的关键字以及基本语法. 1.  #import #import <> 从syste ...

  2. Object C学习笔记22-#define 用法

    上一篇讲到了typedef 关键字的使用,可以参考文章 Object C 学习笔记--typedef用法 .而在c中还有另外一个很重要的关键字#define. 一. #define 简介 在C中利用预 ...

  3. Object C学习笔记21-typedef用法

    在上一章的学习过程中遇到了一个关键字typedef,这个关键字是C语言中的关键字,因为Object C是C的扩展同样也是支持typedef的. 一. 基本作用 typedef是C中的关键字,它的主要作 ...

  4. Object C学习笔记18-SEL,@ selector,Class,@class

    本章是对上一章<<Object C学习笔记17-动态判断和选择器>>的一点补充,所以比较简单点. 一. SEL 类型 在上一篇介绍了几个方法,都只是介绍了其使用方式但是没有具体 ...

  5. Object C学习笔记17-动态判断和选择器

    当时学习Object C的时被人鄙视了一顿,说使用.NET的思想来学Object C就是狗屎:不过也挺感谢这位仁兄的,这让我学习的时候更加的谨慎.今天的学习笔记主要记录Object C中的动态类型相关 ...

  6. Object C学习笔记10-静态方法和静态属性

    在.NET中我们静态使用的关键字static有着举足轻重的作用,static 方法可以不用实例化类实例就可以直接调用,static 属性也是如此.在Object C中也存在static关键字,今天的学 ...

  7. Object C学习笔记24-关键字总结(转)

    学习Object C也有段时间了,学习的过程中涉及到了很多Object C中的关键字,本文总结一下所涉及到的关键字以及基本语法. 1.  #import #import <> 从syste ...

  8. Object C学习笔记15-协议(protocol)

    在.NET中有接口的概念,接口主要用于定义规范,定义一个接口关键字使用interface.而在Object C 中@interface是用于定义一个类的,这个和.NET中有点差别.在Object C中 ...

  9. Object C学习笔记13-Dictionary字典

    通过Array数组和Set集合的学习和理解,可以想象得到Dictionary也分为两种情况了,那就是可变和不可变两种类型的.的确如此,在Object C中提供了两个字典类,分别为NSDictionar ...

随机推荐

  1. 关于WCF一些基础。

    关于WCF Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .N ...

  2. webconfig的设置节点几个说明

    有助于深入理解webconfig <?xml version="1.0" encoding="utf-8" ?> <configuration ...

  3. utils object doesn,t exists中毒后,就删除了.JS文件后台就出现了前面的英文。请问怎么解决

    明显是你删了js丢失了函数了...从备份里还原一份.js出来放进去,前台也不能删,如果遇到名字冲突,修改一下名字即可

  4. excel - 相等判断

    函数使用例子: =IF(EVALUATE(B23)=C23,"正确","错误") 即判断单元格'B23'与'C23'是否相等,若为true,则返回"正 ...

  5. java Enum 用法示例

    public enum MyEnum { Monday, Tuesday, Wednesday, Thursady, Friday, Saturday, Sunday; public static v ...

  6. ajax无刷新方式收集表单并提交表单

    ajax无刷新方式收集表单有两种方式, 一个是使用html5的FormData.一个是传统的方式. 一,FormData,在主流的浏览器中可以用,IE不好用啊. 另外,FormData使用有两个条件, ...

  7. centos 用户切换

    在系统的/etc/.bash_profile中已经配置了各种环境变量. 用账户a登陆,ldd xxx.so查看一切链接正常. 用账户root登陆,ldd xxx.so查看一切链接正常. 用账户a登陆, ...

  8. 【USACO 2.2.4】派对灯

    [描述] 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄 ...

  9. 零散的笔记:jquery中的事件

    1.替代mouseover和mouseout的事件 jquery的mouseover和mouseout事件在移到子页面时也会触发,这在移到一级菜单弹出二级菜单,移到二级菜单时一级菜单也要显示时,这两个 ...

  10. @font-face扒站的步骤

    今天模仿百度首页手机版的时候遇到的@font-face的问题,现在整理一下. 问题:图中红色区域,在拷贝F12样式的时候,并没有出现这些小图标.        图1:百度的效果             ...