您的当前位置:首页正文

Objective-C之plist文件

来源:华佗小知识

plist文件简介

plist文件是IOS系统下一种常用的文件,全称Property List属性列表文件,扩展名是.plist,常用来保存配置信息。

简单的plist文件:
plist.jpg

简单的demo:
在ViewController.m文件的- (void)viewDidLoad函数中

    //1、获取路径
    NSString *strPath = [[NSBundle mainBundle]pathForResource:@"student.plist" ofType:nil];
    //2、读取文件
    NSArray *arr = [NSArray arrayWithContentsOfFile:strPath];
//  NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:strPath];
    //3、解析数据
    
    for (NSDictionary *dict in arr) {  
        NSString *name1 =[dict objectForKey:@"name"];
        NSLog(name1,nil);
        NSString *sex1 = dict[@"sex"];
        NSLog(sex1,nil);
        NSNumber*age1 = dict[@"age"];
        NSLog(@"%@",age1);

    }