Plist 保存用户的配置数据
1.创建Plist文件,用Dictionary 读出数据
? ??//获取沙盒目录
? ? NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
?? ?
? ? NSString *path=[paths objectAtIndex:0];
?? ?
? ? //得到完整的文件名称
? ? NSString *filepath = [path stringByAppendingString:@"/people.plist"];
?? ?
? ? //创建 Dictionary 对象
? ? NSDictionary *dic = @{@"age":@18,@"name":@"jack"};
?? ?
? ? //将字典写入plist文件
? ? [dic writeToFile:filepath atomically:YES];
?? ?
? ? //根据文件得到Dictionary 对象
? ? NSDictionary *getDic = [NSDictionarydictionaryWithContentsOfFile:filepath];
? ??
? ? NSLog(@"path:%@,数据:%@",filepath,getDic);
打印结果
??
2016-04-17 10:51:40.078 Plist_01[7370:546065] path:/Users/yefeng/Library/Developer/CoreSimulator/Devices/43183B3B-C46A-42E2-8605-538049FE5A42/data/Containers/Data/Application/FDEB9A5F-5860-423C-ADF6-3BC4494BB71B/Documents/people.plist,数据:{
? ? age = 18;
? ? name = jack;
}