Property list 概述
2015-08-11 08:34
260 查看
plist是一种序列化plist是Cocoa环境中用来保存数据的标准数据格式plist是xml文档
*)arrayWithContentsOfFile:(NSString*)
+ (NSDictionary
*)dictionaryWithContentsOfFile:(NSString *)
NSBundle *bundle = [NSBundle
mainBundle];
NSString *path = [bundle pathForResource:@"imageData"
ofType:@"plist"];加载plist文件
_images = [NSArray
arrayWithContentsOfFile:path];- (NSArray *)images
{
if (_images ==
nil) {
NSBundle *bundle = [NSBundle
mainBundle];
NSString *path = [bundle
pathForResource:@"imageData" ofType:@"plist"];
_images = [NSArray
arrayWithContentsOfFile:path];
}
return
_images;
}
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>name</key> <string>biaoqingdi</string> <key>desc</key> <string>表情弱爆了</string> </dict> <dict> <key>name</key> <string>bingli</string> <key>desc</key> <string>病例</string> </dict> <dict> <key>name</key> <string>chiniupa</string> <key>desc</key> <string>吃牛扒</string> </dict> <dict> <key>name</key> <string>wangba</string> <key>desc</key> <string>王八</string> </dict> <dict> <key>name</key> <string>danteng</string> <key>desc</key> <string>蛋疼</string> </dict> </array> </plist>如果对象是array或者dictionary需要使用writeToFIle写plist,具体参看api文档。解析plist :+ (NSArray
*)arrayWithContentsOfFile:(NSString*)
aPath
+ (NSDictionary
*)dictionaryWithContentsOfFile:(NSString *)
path获得Plist文件的全路径
NSBundle *bundle = [NSBundle
mainBundle];
NSString *path = [bundle pathForResource:@"imageData"
ofType:@"plist"];加载plist文件
_images = [NSArray
arrayWithContentsOfFile:path];- (NSArray *)images
{
if (_images ==
nil) {
NSBundle *bundle = [NSBundle
mainBundle];
NSString *path = [bundle
pathForResource:@"imageData" ofType:@"plist"];
_images = [NSArray
arrayWithContentsOfFile:path];
}
return
_images;
}
相关文章推荐
- linux下的解压命令详解
- 架构师速成8.3-可用性之分库分表
- 各大网站CSS代码初始化集合
- Tomcat+Servlet登录页面实例
- 利用keepalived和haproxy配置mysql的高可用负载均衡
- CoreOS与Mirantis联手推动OpenStack与Linux容器的集成
- docker菜鸟笔记——总结1
- CentOS下安装配置SVN服务器并自动同步到web目录
- 架构师速成8.3-可用性之分库分表
- Ceph 整合OpenStack kilo 遇到问题解决
- 管理和监控
- 管理和监控
- commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现
- commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现
- 近期将会暂停服务的网站一览 - 做好数据迁移的准备哦^_^
- 2016.03.27跟进-将会暂停服务的网站一览 - 做好数据迁移的准备哦
- vs2013发布网站
- 转载---linux运维相关
- Linux系统管理(一)安装Linux操作系统
- 【Powershell】【Hash】hash表的使用技巧