屬性列表(plist)
- plist的文件名不能叫做“info”窃蹋、“Info”之類的,這是因?yàn)榕c系統(tǒng)屬性文件重名
- 屬性列表是一種XML格式的文件,拓展名為plist
- 如果對象是NSString序苏、NSDictionary、NSArray佳吞、NSData贮勃、NSNumber等類型,就可以使用writeToFile:atomically:方法直接將對象寫到屬性列表文件中
Plist不能存儲自定義對象
- 成功后會寫入到
Documents
文件中(app)
- xcode中plist文件創(chuàng)建步驟:NewFile —— IOS —— Resource —— Property List
plist存儲應(yīng)用舉例
- 加載plist
//獲取Plist文件的全路徑
NSString *path = [[NSBundle mainBundle] pathForResource:@"shops" ofType:@"plist"];
//加載plist文件
_shops = [NSArray arrayWithContentsOfFile:path];
- 屬性列表——?dú)w檔NSDictionary
- 將數(shù)據(jù)封裝成字典
- 將字典持久化到Documents/stu.plist文件中
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:@"15013141314" forKey:@"phone"];
[dict writeToFile:path atomically:YES];
- 屬性列表——恢復(fù)NSDictionary
- 讀取Documents/stu.plist的內(nèi)容滴劲,實(shí)例化NSDictionary
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
NSLog(@"phone:%@", [dict objectForKey:@"phone"]);
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者