归档步骤:
1、将一个NSDictionary对象归档到一个plist属性列表中
<1>
首先要将数据封装成字典:
NSMutableDictionary
* dict = [NSMutableDctionary dictionary];
[dict
setObject:@"烟灰" forKey:@"name"];
[dict
setObject:@"1234567" forKey:@"phoneNumber"];
[dict
setObject:@"24" forKey:@"age"];
<2>
将字典永久的保存在文件中
[dict
writeToFile:path atomically:YES]; ( path
为数据要写入的文件中,例如:/Users/apple/Library/Application Support/iPhone
Simulator/6.0/Applications/Documents/stu.plist)
2、读取属性列表
读取属性列表的时候要恢复NSDictionary对象
NSDictionary * dict = [NSDictionary
dictionaryWithContentsOfFile:path];
NSLog(@"name:%@",[dict objectForKey:@"name"]);
NSLog(@"phoneNumber:%@",[dict objectForKey:@"phoneNumber"]);
NSLog(@"age:%@",[dict objectForKey:@"age"]);
流程图如下:
IOS中将对象属性列表归档成一个plist文件中
时间: 2024-07-30 10:19:39