//

//  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. win7 打开方式不能添加程序

    打开注册表,找到“HKEY_CLASSES_ROOT\Applications\”中,查看相应的程序的“\shell\open\command”项中的数据是否正确:如果不正确,就修改正确,之后再添加程 ...

  2. tabswitch

    <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...

  3. MVC使用Exception过滤器自定义处理Action的的异常

    1.继承FilterAttribute ,IExceptionFilter自定义处理 /// <summary> /// 登录错误自定义处理 /// </summary> pu ...

  4. ViewPager 嵌套Listview 让Listview响应 ViewPager 左右滑事件

    一段拦截判断而已.   之前一直误解了一个拦截的描述.导致搞了半天. 结论: onInterceptTouchEvent 返回true,就由本身View的onTouchEvent进行事件消费. /** ...

  5. 困扰:C#.net 连接Oracle11g 不报错但是在connection时出现 ServerVersion 引发了“System.InvalidOperationException”类型的异常

    今天在使用VS2008 32位 连接 64位的Oracle11g的数据库时出现 “conn.ServerVersion”引发了“System.InvalidOperationException”类型的 ...

  6. IntelliJ IDEA提示忽略大小写

    1.打开设置(CTRL+ALT+S) 2.搜索Code Completion,点击Case sensitive completion后面的选择框,选中None

  7. Eclipse 将Java项目转为Dynamic web project

    1.打开项目根目次下的.project 在<buildSpec>节点下是否存在 <buildCommand> <name>org.eclipse.wst.commo ...

  8. CentOS安装rar、unrar解压缩软件的方法

    闲话不说,centos上如何安装rar.unrar在线解压缩软件呢?如果您的centos是32位的,执行如下命令: wget http://www.rarsoft.com/rar/rarlinux-3 ...

  9. type和instance

    获取对象类型 type(object) >>> test_data = [1, 2, 3] >>> type(test_data) <type 'list'& ...

  10. WEB兼容性之JS

    1. 获取iframe的window对象 //三种方法 window.iframeName window.frames[iframeName] document.getElementById(ifra ...