//

//  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. http方法

    http method(方法):1.get 从服务器获取资源2.post 向服务器发送资源3.put 向服务器推送资源4.delete 告诉服务器删除某个资源5.head 告诉服务器返回数据时不需要返 ...

  2. Asp.net 主题 【2】

    通常我们经常看到网页,一些软件提供换肤功能,各种主题间切换.ASP.NET 2.0 中可以用Theme和skin以及CSS轻松实现这个功能. 首先简单介绍一下三种技术:主题(Theme)技术,面板(s ...

  3. centos 6.X 安装输入法

    1.打开终端 su 输入 密码 yum install "@Chinese Support" 2.接下来是启用中文输入法的操作 系统 ->首选项 ->输入法 3.在弹出 ...

  4. ubuntu10.04版本下android源码的编译

    首先是网址:http://software.intel.com/en-us/blogs/2012/03/06/hands-on-notesbuild-android-x86-ics-4-virtual ...

  5. ActiveX相关

    ActiveX 1.创建ActiveXhttp://blog.csdn.net/fww330666557/article/details/6533118 继承IObjectSafety接口http:/ ...

  6. 《asp.net mvc3 高级编程》第四章 模型

    一,建立简单的Model 在Models文件夹上右击鼠标,选择“添加”,“类”,如下图所示: 建立三类相关联的类代码如下: public class Album { public virtual in ...

  7. MongoDB-固定集合 capped collection 操作 介绍

    固定集合:capped collection 是性能出色的固定大小的集合,以LRU算法淘汰记录,自助维护集合中的对象的插入顺序,创建时预先制定大小,空间使用完,心对象取代旧的对象,保持最新的数据. 可 ...

  8. python学习第十七天 --定制类

    何为定制类? Python的class允许定义许多特殊方法,可以让我们非常方便地生成特定的类.在类中应用或者重写python的特殊方法,得到的类,就是定制类. 大家都知道print的用法.见下面例子 ...

  9. C语言基础学习运算符-逻辑运算符

    逻辑运算符 逻辑运算符是根据表达式的值来返回真值或是假值.C语言中的逻辑运算符就三种,如下表所示: 列如: 更多学习内容,就在码芽网http://www.mayacoder.com/lesson/in ...

  10. C++学习笔记4——类的封装(2)

    简介: 重载的运算符是具有特殊名字的函数:它们的名字由关键字operator和其后要定义的运算符号共同组成.其中一元运算符有一个参数,二元运算符有两个参数. 可以被重载的运算符 + - * / % ^ ...