您的位置:首页 > 移动开发 > Objective-C

Objective-C中读取Plist文件数据

2018-03-21 22:24 661 查看
开发环境: 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 : 302018-03-21 22:23:43.875773+0800 TOCPlistb[1609:64740] The name values is : liming2018-03-21 22:23:43.875962+0800 TOCPlistb[1609:64740] The sex values is : male
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: