NDMutableDictionary

NSDictionary以及NSMutableDictionary的用法

最后都变了- 提交于 2019-12-07 08:45:00
1、NSDictionary (不可变字典) 字典的初始化 //一个key - value NSDictionary *dic1 = [NSDictionary dictionaryWithObject:@"@123" forKey:@"key1"]; //两个以上 key - value NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2" ,nil]; //用字典为另一个子字典初始化 NSDictionary *dic3 = [NSDictionary dictionaryWithDictionary:dic1] //新方法赋值 NSDictionary *dic4 = @{@"key1": @"value1",@"key2": @"value2"}; //以为件内容初始化一个字典 NSDictionary *dic5 = [NSDictionary dictionaryWithContentsOfFile:path]; //将字典的key转成一个枚举对象,用于遍历 NSEnumerator *enumerator = [dic4 keyEnumerator]; 字典的常用方法 //返回字典键值对的个数 NSInteger count