swift - 如何在 Swfit 中使用 UserDefaults 保存和加载 UIimage?
问题描述
func saveImage(图像:UIImage,键:字符串){
UserDefaults.standard.set(image, forKey: key)
}
func getImage(key : String) -> UIImage {
let image = UserDefaults.standard.object(forKey: key) as? UIImage
return image!
}
解决方案
UserDefaults 可以存储数据、字符串、数字、日期、数组和字典。如果要存储图片,可以将图片转成base64字符串再存储。
推荐阅读
- php - 根据仅保留最新的值删除数组中的重复对象(基于时间戳的第二个值)
- python - Selenium 用一个扭曲的 Python 滚动到视图中
- python - python在clojure中的累积等价物
- java - Docker compose 无法在 java 和 mysql 容器之间建立连接
- python - 到达某一行后如何停止程序?
- python - python 3.8中的Tensorflow安装错误
- sql - DAX 使用 AVERAGE 计算滚动平均值
- c++ - 浮点类型表示
- python - SyntaxError: 无效的语法没有解决方案
- android - 如何让cordova、Java SDK和Android SDK协同工作?