// NSMutableDictionary
//1.创建
NSMutableDictionary *nsm = [NSMutableDictionary dictionary];
nsm.dictionary=@{@"zs":@"张三",@"ls":@"李四"};
// 2.删除
[nsm removeObjectForKey:@"zs"];
// 3.修改 会覆盖原来的
//[nsm setObject:@"------李四--------" forKey:@"ls"];
// 推荐用法
nsm[@"ls"] = @"------李四--------";
// 4. 删除所有
[nsm removeAllObjects];
// 5.遍历
[nsm enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSLog(@"%@",obj);
}];
// NSDictionary 读写文件
// 创建路径
NSString *path = @"/Users/fendou/Desktop/练习代码/20141222/dictionary.plist";
// 获得数据源
NSDictionary *dic1 = @{@"zs":@"张三",@"ls":@"李四",@"ww":@"王五"};
NSDictionary *dic2 =@{@"1":@"1",@"2":@"2",@"3":@"3"};
NSDictionary *dic3 =@{@"11":@"11",@"22":@"22",@"33":@"33"};
NSArray *array = @[dic1,dic2,dic3];
BOOL isOk = [array writeToFile:path atomically:YES];
NSLog(@"%i",isOk);
// 读取文件
NSArray *a = [NSArray arrayWithContentsOfFile:path];
// 循环NSArray获得字典
for (NSDictionary *d in a)
{
// 循环NSDictionary获得数据
for (NSString *s in d)
{
NSLog(@"读取Array里的NSDictionary---- >%@",d[s]);
}
}