// 数组(NSArray/NSMutableArray)
// 不可变数组
NSArray *array1 = @[@"a",@"b",@"c",@"d"];
//创建
NSLog(@"array1 = %@",array1);
// 数组元素个数.count
NSLog(@"count = %ld",array1.count);
// 通过下标访问数组里面的元素
NSString *str = array1[0];
NSLog(@"str = %@",str);
// 可变数组NSMutableArray
NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];
NSLog(@"mutableArray = %@",mutableArray);
// 元素个数:count
NSLog(@"count = %ld",mutableArray.count);
// 添加个数
[mutableArray addObject:@"5"];
NSLog(@"已添加----%@",mutableArray);
// 移除元素
[mutableArray removeObject:@"3"];
NSLog(@"已移除----%@",mutableArray);
// 字典(存放多个键值对(key-value)的一种数据类型)
// (NSDictionary,NAMutableDictionary)
// 不可变字典NSDictionary
NSDictionary *dict = @{@"key1":@"value1",@"key2":@"value2",@"key3":@"value3"};
NSLog(@"dict = %@",dict);
NSString *string = [dict objectForKey:@"key1"];
NSLog(@"string = %@",string);
// 所有的key值,所有的value值
NSLog(@"allkeys = %@,@allvalues = %@",dict.allKeys,dict.allValues);
}
return 0;
}
网友评论