【问题标题】:How to use enum values as columns in a GRDB Record?如何使用枚举值作为 GRDB 记录中的列?
【发布时间】:2021-08-12 21:45:12
【问题描述】:

我想记录 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,为什么这使它不可解码?

【问题讨论】:

    标签: ios swift grdb


    【解决方案1】:

    当我对 RecordType 采用 Codable 时,这种情况就消失了。找到答案here

    extension RecordType: DatabaseValueConvertible, Codable {}
    

    【讨论】:

      猜你喜欢
      • 2012-11-24
      • 2021-06-29
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      相关资源
      最近更新 更多