//1.使用实例方法创建字典
NSDictionary *dictionary = [[NSDictionary alloc]
initWithObjectsAndKeys:
@"V1", @"Kk1",
@"V2", @"K2",
@"V3", @"K",
@"oo", @"xx",
@"sfasf", @"q",
nil];
NSLog(@"%@", dictionary);
//2.使用类方法创建字典
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"hongloumeng", @"k1", @"xiyouji", @"k2", @"shuihuzhuan", @"k3", @"sanguoyanyi", @"k4", nil];
NSLog(@"%@", dic);
//创建保存所有key的数组
NSArray *keyArray = [NSArray arrayWithObjects:@"k1", @"k2", @"k3", nil];
//创建保存所有value的数组
NSArray *valueArray = [NSArray arrayWithObjects:@"v1", @"v2", @"v3", nil];
NSDictionary *diction = [NSDictionary dictionaryWithObjects:valueArray forKeys:keyArray];
NSLog(@"%@", diction);
//3.使用一个文件创建字典对象
NSDictionary *d = [NSDictionary dictionaryWithContentsOfFile:@"/Users/lanou3g/Desktop/OC语言/OC作业/第五讲/NSDictionary不变字典/NSDictionary不变字典/dict.plist"];
NSLog(@"%ld", [d count]);
NSLog(@"%@", d);
//4.使用指定路径创建字典对象
// NSDictionary *di = [NSDictionary dictionaryWithContentsOfURL:@"<#string#>"];
// NSLog(@"%@", di);
//根据key取出一个值 key值
NSString *str = [d objectForKey:@"123"];
NSLog(@"%@", str);
//取出字典中所有的key
NSArray *allKeyArray = [d allKeys];
NSLog(@"%@", allKeyArray);
//取出字典中所有的value
NSArray *allValueArray = [d allValues];
NSLog(@"%@", allValueArray);
//根据key枚举器取值
NSEnumerator *enumerator = [d keyEnumerator];
NSString *s = nil;
while (s = [enumerator nextObject]) {
NSLog(@"%@", s); //输出的是key值
NSLog(@“%@“, [d objectForKey:s]);//输出内容
}