points: Int enum CodingKeys: String, CodingKey { case name case points } } extension GroceryProduct: Decodable { init(from: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) self.name = try values.decode(String.self, forKey: .name) self.points = try values.decode(Int.self, forKey: .points) } } extension GroceryProduct: Encodable { func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.name, forKey: .name) try container.encode(self.points, forKey: .points) } } 冗⻑な記述を 書くのを避けたい 処理する段階に応じて できるだけ冗⻑さを避ける