小总结:数组,集合,字典

数组:

NSArray *array2 = [NSArray arrayWithObject:@"one"];//只有一个元素的数组
NSArray *array3 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];//有多个元素的数组
NSArray *array4 = @[@"one", @"two", @"three"];//优化后的方法,最常用的
NSArray *array5 = [NSArray arrayWithArray:array4];//生成数组的副本

NSMutableArray *array1 = [NSMutableArray array];//空数组,有意义
NSMutableArray *array2 = [NSMutableArray arrayWithCapacity:100];//预估值
NSMutableArray *array4 = [NSMutableArray arrayWithObjects:@"one", @"two", @"three", nil];//标准方法,最常用的

集合:

NSSet *set1 = [NSSet setWithObjects:@"one",@"two",@"three",@"two", nil];//标准创建方法
NSSet *set2 = [NSSet setWithSet:set1];//副本创建
NSArray *str = @[@"one",@"two",@"three",@"two"];
NSSet *set3 = [NSSet setWithArray:str];//数组转换成集合

NSMutableSet *set1 = [NSMutableSet set];//空集合,有意义
NSMutableSet *set2 = [NSMutableSet setWithCapacity:100];//预估值100,不是上限,突破后效率会降低
NSMutableSet *set3 = [NSMutableSet setWithObjects:@"1",@"2",@"3", nil];//创建集合的同时初始化```

####字典:

NSDictionary dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"one",@"1"/先写值,后写关键字*/,@"two",@"2", nil];//创建字典的标准方法
NSDictionary *dic2 = @{@"1"😡"one",@"2"😡"two"};//优化方法,最常用
NSArray *a1 = @[@"one",@"two",@"three"];
NSArray *a2 = @[@"1",@"2",@"3"];
NSDictionary *dic3 = [NSDictionary dictionaryWithObjects:a1 forKeys:a2];//将数组转换成字典,两个数组的关键字和值必须对应
NSDictionary *dic4 = [NSDictionary dictionaryWithDictionary:dic3];//创建字典的副本

NSMutableDictionary *dict1 = [NSMutableDictionary dictionary];//空字典,有意义,可以添加键值对
NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithCapacity:100];//预估值创建
NSMutableDictionary *dict3 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"one",@"1",@"two",@"2",@"three",@"3", nil];//存储在堆上;标准方法

posted @ 2017-08-23 20:41  笑笑就好90  阅读(199)  评论(0编辑  收藏  举报