码迷,mamicode.com
首页 > 其他好文 > 详细

[OC Foundation框架 - 21] NSSet集合 & 集合之间的转换

时间:2014-11-24 20:40:44      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

A.NSSet
跟NSArray一样,不可变
NSArray 自然顺序
NSSet是无序的
NSSet不允许存入重复元素,可以用来过滤重复元素
 
也有可变的NSMutableSet
 
B.集合转换
       
 1  // 1.NSArray 转换成 NSMutableArray
 2         NSArray *array = @[@"one", @"two", @"three"];
 3         NSMutableArray *muArray = [NSMutableArrayarrayWithArray:array];
 4         NSLog(@"muArray = %@", muArray);
 5        
 6        
 7         // 2.NSDictionary 转换成 NSMutableDictionary
 8         NSDictionary *dic = @{@"one":@"1", @"two":@"2", @"three":@"3"};
 9         NSMutableDictionary *muDic = [NSMutableDictionarydictionaryWithDictionary:dic];
10         NSLog(@"muDic = %@", muDic);
11        
12         // 3.NSArray -> NSSet -> NSMutableSet
13         NSSet *set = [NSSetsetWithArray:array];
14         NSMutableSet *muSet = [NSMutableSetsetWithSet:set];
15         NSLog(@"muSet = %@", muSet);
16        
17         // 4.NSDcitionary -> NSArray
18         NSArray *allKeys = [dic allKeys];
19         NSLog(@"allKeys = %@", allKeys);
20         NSArray *allValues = [dic allValues];
21         NSLog(@"allValues = %@", allValues);
22        
23         // 5.NSString -> NSArray
24         NSString *str = @"www.baidu.com";
25         NSArray *array2 = [str componentsSeparatedByString:@"."];
26         NSLog(@"array2 = %@", array2);
 
 

[OC Foundation框架 - 21] NSSet集合 & 集合之间的转换

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/hellovoidworld/p/4119434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!