iosswiftgrdb

How to use enum values as columns in a GRDB Record?


I want to make record of 4 different types. I have the following code

import GRDB

enum RecordType: Int16 {
    case video, image, text, rep
}
extension RecordType: DatabaseValueConvertible {}

struct Record: Codable, FetchableRecord, PersistableRecord {
    var id: Int64?
    var type: RecordType
}

Right now it complains Type 'Record' does not conform to protocol 'Decodable'

Of course when I remove the type from the struct, that complaint goes away. Since type is technically Int16 why does this make it not Decodable?


Solution

  • When I adopt Codable to the RecordType as well this goes away. Found the answer here

    extension RecordType: DatabaseValueConvertible, Codable {}