集合之间的相互转换

//

//  main.m

//  11-集合相互转换

//

//  Created by apple on 14-3-21.

//  Copyright (c) 2014年 apple. All rights reserved.

//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])

{

    @autoreleasepool {

        

        //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);

        

    }

    return 0;

}

原文地址:https://www.cnblogs.com/supper-Ho/p/6185706.html