当前位置:网站首页>Store to-do items locally (improve on to-do items)
Store to-do items locally (improve on to-do items)
2022-07-25 09:53:00 【yueliangmua】
utilize UserDefault Store content in the system sandbox , adopt JSON Encoding and decoding realize the persistent storage of data , Every time you open the application, the operation will be saved to the local .
Find sandbox path
print(NSHomeDirectory())use command+ Space copy path to find folder , open Library Folder , And on again Preferences Folder , Open the inside plist file , You can see the stored content , Click on Type You can see the basic type of storage .
Because it is self-defined Todo type , So it can't be saved plist file , Need to transfer data type , use json code , however Todo The type must comply with the protocol of encoding and decoding .
func saveData(){
// The local store
do{
let data = try JSONEncoder().encode(todos)
UserDefaults.standard.set(data, forKey: kTodosKey)// Because it is Todo Type cannot be saved plist file , Need to transfer data type , use json code
}catch{
print(" Coding errors ")
}
}key Define for yourself
In the add, modify and delete function of the to-do list, call the storage function to code and store , stay ViewDidLoad() Call the decoding function at the beginning to decode the read content .
if let data = UserDefaults.standard.data(forKey: kTodosKey){
if let todos = try? JSONDecoder().decode([Todo].self, from: data){
self.todos = todos
}else{
print(" Decoding failed ")
}
}// Take the data
边栏推荐
- MLX90640 红外热成像仪测温模块开发说明
- MLX90640 红外热成像仪测温模块开发笔记(一)
- 从鱼眼到环视到多任务王炸——盘点Valeo视觉深度估计经典文章(从FisheyeDistanceNet到OmniDet)(下)
- Principle analysis of self supervised depth estimation of fish eye image and interpretation of omnidet core code
- Evolution based on packnet -- review of depth estimation articles of Toyota Research Institute (TRI) (Part 1)
- CDA Level1知识点总结之业务分析报告与数据可视化报表
- First knowledge of opencv4.x --- image template matching
- Learning new technology language process
- CCF 201509-4 高速公路
- 相机姿态估计
猜你喜欢
随机推荐
Sort out personal technology selection in 2022
深度估计自监督模型monodepth2论文总结和源码分析【理论部分】
【RNN】剖析RNN 之 从RNN-(Simple|LSTM) 到 序列生成 再到 seq2seq框架(encoder-decoder,或称为seq2seq)
CDA LEVELⅠ2021新版模拟题一(附答案)
[data mining] Chapter 2 understanding data
一个硬件攻城狮的经济学基础
[deep learning] convolutional neural network
【Tensorflow2安装】Tensorflow2.3-CPU安装避坑指南!!!
初识Opencv4.X----图像直方图均衡
【降维打击】希尔伯特曲线
初识Opencv4.X----为图像添加椒盐噪声
ADC介绍
MLX90640 红外热成像传感器测温模块开发笔记(三)
Hyperautomation for the enhancement of automation in industries 论文翻译
matlab的find()函数的一些用法(快速查找符合条件的值)
Defect detection network -- hybrid supervision (kolektor defect data set reproduction)
基于PackNet的演进——丰田研究院(TRI)深度估计文章盘点(上)
Camera attitude estimation
【深度学习】自编码器
pytorch使用tensorboard实现可视化总结







![[deep learning] self encoder](/img/7e/c3229b489ec72ba5d527f6a00ace01.png)

