1. 概念

  用于存储串行化对象,xml格式,存储到plist文件中。

2. 用途

  存储用户设置。

3. 优点

  • 程序运行时可动态创建和读写。

4. 使用说明

4.1. 获取plist文件

NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentPath stringByAppendingPathComponent:@"student.plist"];

4.2. 存储数据

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSDictionary *stu1= @{@"idNum":@"",@"name": @"jereh"};
[dict setValue:stu1 forKey:@"stu1"];
// 新数据写入plist文件
[dict writeToFile:filePath atomically:YES];

4.3. 读取数据

NSMutableDictionary *dicNow = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
int idNum = [[dicNow objectForKey:@"idNum"] intValue];
NSString *name = [dicNow objectForKey:@"name"];
05-11 11:19