0
点赞
收藏
分享

微信扫一扫

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

@"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-

举报

相关推荐

0 条评论