集合、可变集合
2015-07-27 08:32
204 查看
<pre name="code" class="objc">int main(int argc, const char * argv[]) { @autoreleasepool { // 4 NSArray -> NSSet NSArray * array = @[@"one",@"two",@"three"]; NSSet * set = [NSSet setWithArray:array]; NSLog(@"%@",set); // 5 NSDictionary -> NSArray NSDictionary * dic = @{ @"name":@"Jack", @"age":@"18", @"ID":@"1001" }; NSArray * keysArray = [dic allKeys]; NSArray * valuesArray = [dic allValues]; //6 字符串转换成数组 // 创建字符串 NSString * str = @"I am studying "; // 传入字符参数分割字符串 NSArray * arrStr = [str componentsSeparatedByString:@"am"]; NSLog(@"arrStr %@",arrStr); } return 0; }
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { NSSet * set = [[NSSet alloc] initWithObjects:@"one",@"two",@"three",@"four",@"one", nil]; NSLog(@"%@",set); NSCountedSet// NSSet中不能够存储重复的数据 NSUInteger count = [set
count]; NSLog(@"coutn %lu",count); BOOL isContain = [set containsObject:@"t"]; if (isContain) { NSLog(@"contain"); } else { NSLog(@"not contain"); } } return 0;}
int main(int argc, const char * argv[]) { @autoreleasepool { NSMutableSet * set = [[NSMutableSet alloc] initWithObjects:@"one",@"two", nil]; NSLog(@"%@",set); // 增加值 [set addObject:@"three"]; NSLog(@"%@",set); // 删除值 [set removeObject:@"two"]; NSLog(@"%@",set); // 删除所有 [set removeAllObjects]; NSLog(@"%@",set); } return 0; }
相关文章推荐
- 爷爷去世了。
- MySQL command
- struts2 kindeditor teatarea拿不到值问题。
- UEditor扩展上传
- H - Can you answer these queries? - (区间查询更新)
- 阿里云epel源
- Twelves Monkeys (multiset解法 141 - ZOJ Monthly, July 2015 - H)
- this call() apply()理解
- 开源 java CMS - FreeCMS2.3会员我的留言
- OC中可变字典和不可变字典
- 网站的通用注册原型设计
- Android ORMLite 框架的入门用法
- hihocoder 1191 小W与网格 (组合数)
- Android MenuItem 设置文本颜色-TextColor设置
- OC可变数组的创建与简单应用
- C语言中指针和自增运算符结合时的运算顺序问题
- mysql-编译安装cmake
- 遍历数组、数组排序
- iOS开发-Day9-C的复习
- Android学习二:Resources