// 新建文件創(chuàng)建plist文件
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"banks" ofType:@"plist"];
//存儲(chǔ)類型要對(duì)應(yīng) 不然取出為null
NSMutableArray *data = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
NSLog(@"plist文件%@", data);
NSDictionary *dic = data[1];
NSString * bankcode = dic[@"bankcode"];
NSString * bankeng = dic[@"bankeng"];
NSString * bankname = dic[@"bankname"];
NSString * img = dic[@"img"];
NSLog(@"=====%@====%@====%@===%@",bankcode,bankeng,bankname,img);
控制臺(tái)輸出.png
單個(gè)數(shù)據(jù)
//代碼創(chuàng)建plist文件
// 沙盒路徑
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//完整路徑
NSString *doucumentPath = [path objectAtIndex:0];
NSString *plistPath = [doucumentPath stringByAppendingPathComponent:@"test.plist"];
//創(chuàng)建數(shù)據(jù)
NSMutableDictionary * testDic = [NSMutableDictionary dictionary];
[testDic setObject:@"奧迪" forKey:@"車"];
[testDic setObject:@"紅色" forKey:@"車色"];
[testDic setObject:@"京A888888" forKey:@"車牌"];
[testDic setObject:@"奧迪A8" forKey:@"車型"];
//寫入數(shù)據(jù)
[testDic writeToFile:plistPath atomically:YES];
NSMutableDictionary * dic11 = [[NSMutableDictionary alloc]initWithContentsOfFile:plistPath];
NSLog(@"==車===%@==車色==%@+===車牌=%@===車型=%@",dic11[@"車"],dic11[@"車色"],dic11[@"車牌"],dic11[@"車型"]);
控制臺(tái)