作用
Property List用于存储简单的结构数据。
创建Property List文件
在Xcode中,选择New File,选择模板中的Resource,选择Property List,点击next

命名为MyList:

添加数据
可以看到,左边是key,右边是value:

读取
有了数据,就可以根据文件名字读取,具体读取哪个值,可以根据key值读取:
NSString *path = [[NSBundle mainBundle]pathForResource:@"MyList" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path];
NSLog(@"%@",dict);
NSLog(@"the name is %@",[dict objectForKey:@"name"]);
这是读取结果:
2016-06-21 15:07:24.499 MVPDemo2[40460:5045313] {
age = 20;
name = vampire;
stature = 175;
weight = 65;
}
2016-06-21 15:07:24.501 MVPDemo2[40460:5045313] the name is vampire
网友评论