Objective-C中讀取Plist檔案資料
開發環境: Xcode 9.2
開發語言:ObjectiveC
第一步:建立一個工程,然後新建一個Property List檔案.
第二步: 編碼如下:
#import "ViewController.h"
@interfaceViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//獲取Plist檔案路徑
NSString *path = [[NSBundlemainBundle] pathForResource:@"assetlist"ofType:@"plist"];
//獲取Plist檔案內容
NSDictionary *rootDict = [NSDictionarydictionaryWithContentsOfFile: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 {
[superdidReceiveMemoryWarning];
// 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