0

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

4

1 回答 1

1

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

extension RecordType: DatabaseValueConvertible, Codable {}
于 2021-08-12T22:02:28.193 回答