plist文件簡單使用 - iOS

// 新建文件創(chuàng)建plist文件
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"banks" ofType:@"plist"];
//存儲類型要對應 不然取出為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);
控制臺輸出.png
單個數據
//代碼創(chuàng)建plist文件
// 沙盒路徑
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//完整路徑
NSString *doucumentPath = [path objectAtIndex:0];
NSString *plistPath = [doucumentPath stringByAppendingPathComponent:@"test.plist"];


//創(chuàng)建數據
NSMutableDictionary * testDic = [NSMutableDictionary dictionary];
[testDic setObject:@"奧迪" forKey:@"車"];
[testDic setObject:@"紅色" forKey:@"車色"];
[testDic setObject:@"京A888888" forKey:@"車牌"];
[testDic setObject:@"奧迪A8" forKey:@"車型"];
//寫入數據
[testDic writeToFile:plistPath atomically:YES];


NSMutableDictionary * dic11 = [[NSMutableDictionary alloc]initWithContentsOfFile:plistPath];
NSLog(@"==車===%@==車色==%@+===車牌=%@===車型=%@",dic11[@"車"],dic11[@"車色"],dic11[@"車牌"],dic11[@"車型"]);
控制臺
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容