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

iOS之OC随笔-Foudation框架下集合的相互转换

2015-10-13 21:01 435 查看
#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、NSDictionary 转换为 NSMutableDictionary
NSDictionary * dic = @{@"One":@"1",@"Three":@"3"};
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 转换为 NSMutableSet
NSMutableSet * muSet2 = [NSMutableSet setWithArray:array];
NSLog(@"muSet2 %@",muSet2);

//5、NSDictionary 转换为 NSArray
NSArray * allkeys = [dic allKeys];
NSLog(@"allkeys %@",allkeys);
NSArray * allValues = [dic allValues];
NSLog(@"allvalue %@",allValues);

//6、字符串转换为数组
NSString * str = @"sae.fasfas";
NSArray * strArray = [str componentsSeparatedByString:@"."];
NSLog(@"strArray %@",strArray);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: