ios - 如何使用枚举值作为 GRDB 记录中的列?
问题描述
我想记录4种不同的类型。我有以下代码
import GRDB
enum RecordType: Int16 {
case video, image, text, rep
}
extension RecordType: DatabaseValueConvertible {}
struct Record: Codable, FetchableRecord, PersistableRecord {
var id: Int64?
var type: RecordType
}
现在它抱怨Type 'Record' does not conform to protocol 'Decodable'
当然,当我从结构中删除类型时,这种抱怨就消失了。由于类型在技术上是 Int16,为什么这使它不可解码?
解决方案
当我对 RecordType 采用 Codable 时,这种情况就消失了。在这里找到了答案
extension RecordType: DatabaseValueConvertible, Codable {}
推荐阅读
- python - 使用 Pandas,我如何根据第一个空格进行拆分。
- git - 如何在 Cargo 中使用相对 git 子模块路径?
- c# - Selenium 不检索元素的当前文本值
- r - 带有可选年份的日期模式的正则表达式
- filter - 具有多种类型的 Lodash 流式过滤器或 pickBy
- javascript - 一段时间后提交表单的jQuery计数器:如何获取当前值以提交表单?
- mysql - Ruby on Rails:权限被拒绝 - 为“0.0.0.0”端口 80 (Errno::EACCES) 绑定 (2)
- node.js - 如何在linux中使用nodejs访问windows NAS?
- javascript - 对数组对象使用 join 方法以逗号分隔
- css - 在 div 中居中图像 + 调整大小并保持图像的比例