读书人

在Xcode项目中读取plist资料

发布时间: 2012-08-26 16:48:06 作者: rapoo

在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-

读书人网 >移动开发

热点推荐