700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > IOS中将对象属性列表归档成一个plist文件中

IOS中将对象属性列表归档成一个plist文件中

时间:2022-02-12 08:27:42

相关推荐

IOS中将对象属性列表归档成一个plist文件中

归档步骤:

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"]);

流程图如下:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。