Home > front end >  Swift: getting error while decoding using CodingKey
Swift: getting error while decoding using CodingKey

Time:05-29

I have created a model and I need to try to add value to one of the CodingKey's case

struct Model {
  let name: String
  let location: String
  let descriptions: String

}
    
enum CodingKeys: String, CodingKey {

  case name = "NAME"
  case location = "LOCATION"
  case descriptions = "INFO-\(NSLocalizedString("Language", comment: ""))"
    
}
    
init(from decoder: Decoder) throws {

  let container = try decoder.container(keyedBy: CodingKeys.self)
  .
  .
  descriptions = try container.decode(String.self, forKey: .descriptions)
        
}

Now compiler gives me this error

  • Related