iOS中plist的創建,數據寫入與讀取功能創建一個test.plist文件-(void)triggerStorage{NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YE...
iOS中plist的創建,數據寫入與讀取功能創建一個test.plist文件
-(void)triggerStorage
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path=[paths objectAtIndex:0];
NSString *filename=[path stringByAppendingPathComponent:@"test.plist"]; //獲取路徑
NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename]; //讀取數據
NSLog(@"dic2 is:%@",dic2);
//創建一個dic,寫到plist文件里
NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:displayLabel.text,@"IP",nil]; //寫入數據
[dic writeToFile:filename atomically:YES];
//讀文件
NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
NSLog(@"dic is:%@",dic2);
}
版權聲明:歡迎轉載,請註明出處:蝸牛愛課 • 移動互聯網學習平臺