Getting more details on decoding errors

Hello @cbaker6 and thank you for your suggestions. Applied them. much cleaner. I assumed they’re (the nested objects) automatically conform to Hashable. I forgot I need to manually conform them to the protocol.

I think it’s because description is a reserved keyword in Swift. I added custom decoding and it seems to work now. A bit ugly imo, but it works.

struct UserEventErrors: Codable, Hashable {
    let title: [UserEventError]?
    let description: [UserEventError]?
    let hashtags: [UserEventError]?
    let collectionThumb: [UserEventError]?
    let collectionTemplate: [UserEventError]?
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        title = try? values.decode([UserEventError]?.self, forKey: .title)
        description = try? values.decode([UserEventError]?.self, forKey: .description)
        hashtags = try? values.decode([UserEventError]?.self, forKey: .hashtags)
        collectionThumb = try? values.decode([UserEventError]?.self, forKey: .collectionThumb)
        collectionTemplate = try? values.decode([UserEventError]?.self, forKey: .collectionTemplate)
    }
}
1 Like