您的位置:首页 > 移动开发 > IOS开发

iOS中集合的互相转换

2016-03-03 20:50 316 查看
 
//1.NSArray 转换成 NSMutableArray
        NSArray * array =
@[@"one",@"two",@"three"];
        NSMutableArray * muArray = [NSMutableArray
arrayWithArray:array];
        NSLog(@"muarray %@",muArray);
        
        //2.NSDictonary
转换成        NSMutableDictionary
        NSDictionary * dic =
@{@"one":@"1",@"two":@"2"};
        NSMutableDictionary * muDic = [NSMutableDictionary
dictionaryWithDictionary:dic];
        NSLog(@"mudic %@ ",muDic);
        
        //3.NSset
转换成 NSMutableSet
        NSSet * set = [[NSSet
alloc] initWithObjects:@"one",@"two",
nil];
        NSMutableSet *muSet = [NSMutableSet
setWithSet:set];
        NSLog(@"muSet %@",muSet);
        
        
        //4.NSArray
转换成NSSet
        NSMutableSet * muSet2 = [NSMutableSet
setWithArray:array];
        NSLog(@"muSet2 %@",muSet2);
        
        
        //5.NSDictionary
转化成NSArray
        NSArray * allkeys = [dic
allKeys];
        NSLog(@"allkeys %@",allkeys);
        NSArray * allValues = [dic
allValues];
        NSLog(@"allValues %@",allValues);
        
        //6.字符串转换成数组
        NSString * str =
@"www.itacast.cn";
        NSArray * strArray =        [str
componentsSeparatedByString:@"."];
        NSLog(@"strArray %@",strArray);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 集合互转