1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| //保存按钮 NSLog(@"%@",NSHomeDirectory()); NSString *home=NSHomeDirectory(); NSString *docPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES )[0]; NSLog(@"%@",docPath); //文件路径 NSString *filePath=[docPath stringByAppendingPathComponent:@"data.plist"]; //只有具备了writeToFile的对象才能写入plist NSArray *array=@[@1,@2,@"123"]; [array writeToFile:filePath atomically:YES];
//读取 NSString *docPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES )[0]; NSLog(@"%@",docPath); //文件路径 NSString *filePath=[docPath stringByAppendingPathComponent:@"data.plist"]; NSArray *data=[NSArray arrayWithContentsOfFile:filePath]; NSLog(@"%@",data);
|