当前位置:网站首页>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
边栏推荐
- Android & kotlin: puzzle solution
- Verdi 基础介绍
- @2-1 safety index predicted by CCF at the end of December 1, 2020
- 深度估计自监督模型monodepth2论文总结和源码分析【理论部分】
- expect+sh实现自动交互
- First knowledge of opencv4.x --- drawing shapes on images
- Preliminary understanding and implementation of wechat applet bottom navigation bar
- First knowledge of opencv4.x ---- mean filtering
- Segmentation based deep learning approach for surface defect detection
- Some skills to reduce the complexity of program space
猜你喜欢

First knowledge of opencv4.x --- image template matching

First acquaintance with opencv4.x --- ROI interception

@3-2 optimal threshold of CCF 2020-12-2 final forecast

基于PackNet的演进——丰田研究院(TRI)深度估计文章盘点(上)

初识Opencv4.X----图像模板匹配

@2-1 safety index predicted by CCF at the end of December 1, 2020

matlab绘图|坐标轴axis的一些常用设置

Kotlin collaboration: foundation and use of collaboration
![Customize the view to realize the background of redeeming lottery tickets [elementary]](/img/97/53e28673dcd52b31ac7eb7b00d42b3.png)
Customize the view to realize the background of redeeming lottery tickets [elementary]

CCF 201509-4 高速公路
随机推荐
缺陷检测网络--混合监督(kolektor缺陷数据集复现)
Gartner 2022年顶尖科技趋势之超级自动化
First knowledge of opencv4.x --- drawing shapes on images
CCF 201503-3 节日
matlab如何导入大量数据
AI模型风险评估 第1部分:动机
多通道振弦、温度、模拟传感信号采集仪数据查看和参数修改
ARM预备知识
Get to know opencv4.x for the first time --- add salt and pepper noise to the image
~1 CCF 2022-06-2 treasure hunt! Big adventure!
无向连通图邻接表的创建输出广度深度遍历
How to install pytorch—— A most simple and effective method!
从鱼眼到环视到多任务王炸——盘点Valeo视觉深度估计经典文章(从FisheyeDistanceNet到OmniDet)(下)
SD/SDIO/EMMC
初识Opencv4.X----方框滤波
服务器cuda toolkit多版本切换
matlab如何导入大量数据
Creation of adjacency table of undirected connected graph output breadth depth traversal
*7-1 CCF 2015-09-1 sequence segmentation
AMD EPYC 9664旗舰规格曝光:96核192线程 480MB缓存 3.8GHz频率