Objective-C 字典小结
2012-05-11 12:36
218 查看
//创建字典的方法
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];
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];
相关文章推荐
- objective -c OC语法学习小结
- Objective-c语言_不可变字典
- Python中字典的基础知识归纳小结
- objective - c 字典
- objective-C nil,Nil,NULL 和NSNull的小结
- kali密码破解小结(crunch字典生成)
- Objective-C_数据字典,集合
- objective-c字典
- [Objective-C]OC中字典基本概念和常用方法(NSDictionary和NSMutableDictionary)
- objective-c基础教程——学习小结
- [Objective-C]OC中字典基本概念和常用方法
- Objective-C基础之字典
- Objective-C 字典、可变字典
- 谷安kali密码破解小结(crunch字典生成)
- Objective-c语言_可变字典
- Objective-C学习-字典类型 NSDictionary 和 NSMutableDictionary
- 黑马程序员——Objective-C学习之不可变与可变字典(NSDictionary\NSMutableDictionary)
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- objective-c基础教程——学习小结
- objective-c 使用NSNumber 将int float long等数据类型加入到数组或字典中