shuai1234 发表于 2013-1-28 18:09:17

在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 = ;
...
-EOF-
页: [1]
查看完整版本: 在Xcode项目中读取plist文件