一.简介
-
特点
1.Plist是一个可视化属性列表文件.
2.支持的数据类型有:NSArray、NSDictionary、NSData、NSDate、NSNumber、NSString、Boolean.
3.实际数据是以XML格式储存的(可在工程中右键.plist文件 > Open As > Source Code切换XML格式查看编辑). -
建议使用场景
储存程序运行所需的默认数据或配置信息数据(一般程序运行时不修改数据).
二.用法
1.创建/修改Plist数据




2.读取/使用Plist数据
// 获取对应名称Plist的路径
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
// 传入路径取出Plist数据(注意:此处根据根目录的数据类型决定使用NSArray或NSDictionary)
NSArray *plistArr = [[NSArray alloc] initWithContentsOfFile:plistPath];
NSDictionary *plistDict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
网友评论