The API I am using supports multi-language. For instance:
// For Japanese
{
"earthquake_detail": {
"advisory_title_ja": "津波注意報",
"depth_title_ja": "震源深さ",
"depth_value_ja": "30km",
}
}
// For English
{
"earthquake_detail": {
"advisory_title_en": "Tsunami Advisory",
"depth_title_en": "Depth",
"depth_value_en": "30km",
}
}
I am using swift codable to map them to a struct. Is there a way that I can map multiple coding keys to a single variable? Here is my swift struct.
struct EarthquakeDetail: Codable {
var advisoryTitle, depthTitle, depthValue: String?
enum CodingKeys: String, CodingKey {
case advisoryTitle = "advisory_title_ja"
case depthTitle = "depth_title_ja"
case depthValue = "depth_value_ja"
}
}
What I want to obtain is for Japanese this will be the coding keys:
enum CodingKeys: String, CodingKey {
case advisoryTitle = "advisory_title_ja"
case depthTitle = "depth_title_ja"
case depthValue = "depth_value_ja"
}
and for English:
enum CodingKeys: String, CodingKey {
case advisoryTitle = "advisory_title_en"
case depthTitle = "depth_title_en"
case depthValue = "depth_value_en"
}