首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

在Xcode项目中读取plist资料

2012-08-26 
在Xcode项目中读取plist文件?.plist(Property list) 文件即属性列表文件,类似于XML格式的一种配置文件,里

在Xcode项目中读取plist文件

?

.plist(Property list) 文件即属性列表文件,类似于XML格式的一种配置文件,里面可保存序列化的对象。这种plist文件在Mac OS X及相关产品中常见到,下面是在Xcode中如果读取或写入plist文件的示例。

读取一般的plist文件

1

2

3

4

5

6

7

8

9

// 取得文件路径

...

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Shopping-Info"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ofType:@"plist"];

// 读取到一个NSDictionary

NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

// 读取到一个NSArray

NSArray *array = [[NSArray alloc] initWithContentsOfFile:plistPath];

...

?

读取项目主配置文件xxx-Info.plist或Info.plist

1

2

3

4

...

NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];

NSString *URLString = [dict objectForKey:@"Bundle version"];

...

-EOF-

热点排行