当前位置:网站首页>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
边栏推荐
- First knowledge of opencv4.x --- image convolution
- MLX90640 红外热成像传感器测温模块开发笔记(二)
- Preliminary understanding and implementation of wechat applet bottom navigation bar
- MLX90640 红外热成像传感器测温模块开发笔记(三)
- MLX90640 红外热成像仪测温模块开发说明
- CDA Level1知识点总结之业务分析报告与数据可视化报表
- CUDA 解释 - 深度学习为何使用 GPU
- 一个硬件攻城狮的经济学基础
- 数据分析面试记录1-5
- Expect+sh realize automatic interaction
猜你喜欢

初识Opencv4.X----图像卷积

CUDA 解释 - 深度学习为何使用 GPU

First knowledge of opencv4.x --- box filtering

Principle analysis of self supervised depth estimation of fish eye image and interpretation of omnidet core code

matlab如何导入大量数据

CCF 201509-3 模板生成系统

初识Opencv4.X----为图像添加椒盐噪声
![[deep learning] convolutional neural network](/img/36/081f9e38886f5a7ed4d641761db4b7.png)
[deep learning] convolutional neural network

初识Opencv4.X----均值滤波

MLX90640 红外热成像仪测温模块开发笔记(四)
随机推荐
A number converted from a decimal integer to another base
AI模型风险评估 第1部分:动机
CCF 201604-2 俄罗斯方块
CCF 201509-4 高速公路
深度估计自监督模型monodepth2在自己数据集的实战——单卡/多卡训练、推理、Onnx转换和量化指标评估
chmod和chown对挂载的分区的文件失效
括号匹配问题
MLX90640 红外热成像仪测温模块开发笔记(五)
Bracket matching problem
初识Opencv4.X----方框滤波
VCS常用命令
TensorFlow raw_rnn - 实现seq2seq模式中将上一时刻的输出作为下一时刻的输入
基于PackNet的演进——丰田研究院(TRI)深度估计文章盘点(下)
Solve the problem that esp8266 cannot connect mobile phones and computer hotspots
expect+sh实现自动交互
First knowledge of opencv4.x --- image histogram equalization
[data mining] Chapter 3 basis of data analysis
Introducing MLOps 解读(一)
数据分析业务核心
初识Opencv4.X----均值滤波