我想在我的项目中保存和检索UIColor
。我正在使用Cloud-Firestore,并且我尝试过这样的操作,但是它不起作用:
保存:
batch.setData(["textColor": "UIColor.white"], forDocument: listRef)
检索:
let textColor = documentData["textColor"] as! UIColor
但是这给了我cast-error
:
无法将类型'__NSCFString'(0x1de9b9a98)的值强制转换为'UIColor'(0x1de9ecd50)]
正确的方法是什么?
您可以保存由颜色RGB组成的字典,也可以保存十六进制代码。解析之后,使用它初始化您的UIColor。