IOS中将对象属性列表归档成一个plist文件中
歸檔步驟:
1、將一個(gè)NSDictionary對(duì)象歸檔到一個(gè)plist屬性列表中
?? <1> 首先要將數(shù)據(jù)封裝成字典:
???NSMutableDictionary *?dict = [NSMutableDctionary dictionary];
?? [dict setObject:@"煙灰" forKey:@"name"];?
?? [dict setObject:@"1234567" forKey:@"phoneNumber"];
?? [dict setObject:@"24" forKey:@"age"];
?? <2> 將字典永久的保存在文件中
??? [dict writeToFile:path atomically:YES];?( path 為數(shù)據(jù)要寫入的文件中,例如:/Users/apple/Library/Application Support/iPhone Simulator/6.0/Applications/Documents/stu.plist)
2、讀取屬性列表
??? 讀取屬性列表的時(shí)候要恢復(fù)NSDictionary對(duì)象
??? NSDictionary *?dict = [NSDictionary? dictionaryWithContentsOfFile:path];
??? NSLog(@"name:%@",[dict objectForKey:@"name"]);
??? NSLog(@"phoneNumber:%@",[dict objectForKey:@"phoneNumber"]);
??? NSLog(@"age:%@",[dict objectForKey:@"age"]);
?
流程圖如下:
?
?
?
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/angongIT/p/3717977.html
總結(jié)
以上是生活随笔為你收集整理的IOS中将对象属性列表归档成一个plist文件中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: git/ TortoiseGit 在bi
- 下一篇: vim格式化代码