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

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);
 
 
posted @ 2014-11-24 19:22  HelloVoidWorld  阅读(271)  评论(0编辑  收藏  举报