//创建字典的方法
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
@"wtq",@"name1",
@"wtm",@"name2",
@"wtp",@"name3",
nil];
//将字典的值输出来
NSLog(@"new dictionary is %@",[dic objectForKey:@"name2"]);
//如何遍历字典;使用枚举
NSEnumerator *e = [dic objectEnumerator];
id ee;
while (ee=[e nextObject]) {
NSLog(@" enumer %@",ee);
}
//获取字典中的所有值
NSArray *values = [dic allValues];
NSLog(@"all:%@",values);
//保存字典到文件
NSString *filePath = [[[NSBundle mainBundle]resourcePath]
stringByAppendingPathComponent:@"dict.text"];
BOOL success = [dic writeToFile:filePath atomically:YES];
//相反,我们可以用一个文件的内容来填充一个字典
NSDictionary *myDict2 = [NSDictionary dictionaryWithContentsOfFile:filePath];