开发环境: Xcode 9.2
开发语言:ObjectiveC
第一步:创建一个工程,然后新建一个Property List文件.
第二步: 编码如下:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//获取Plist文件路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"assetlist" ofType:@"plist"];
//获取Plist文件内容
NSDictionary *rootDict = [NSDictionary dictionaryWithContentsOfFile:path];
//遍历打印
for(NSString * key in rootDict.allKeys){
NSLog(@"The %@ values is : %@",key, rootDict[key]);
}
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
第三步:运行程序
log如下:
2018-03-21 22:23:43.875518+0800 TOCPlistb[1609:64740] The age values is : 30
2018-03-21 22:23:43.875773+0800 TOCPlistb[1609:64740] The name values is : liming
2018-03-21 22:23:43.875962+0800 TOCPlistb[1609:64740] The sex values is : male