Ваш JSON
должен быть примерно таким
let jsonString = """
{
"id" :"asda",
"key" : "key asd",
"tags" : [
"Mage",
"Marksman"
]
}
"""
ПРИМЕЧАНИЕ: я игнорирую let info : Info
здесь.
И из этой строки перечисление должно быть Mage
, Marksman
.. и так далее
Но вы добавили их, чтобы они были
case Mage = "you like fantacies and tricking people"*
В Enum необработанные значения неявно присваиваются как CodingKeys
Обновите ваш код до
enum Role : String, Decodable {
case tank = "Tank"
case mage = "Mage"
case assasin = "Assassin"
case fighter = "Fighter"
case support = "Support"
case marksman = "Marksman"
var value: String {
switch self {
case .tank:
return "you believe that last person standing wins"
case .mage:
return "you like fantacies and tricking people"
case .assasin:
return "you enjoy living with danger"
case .fighter:
return "you are the warrior that built this town"
case .support:
return "you are a reliable teammate that always appears where you are needed"
case .marksman:
return "you tend to be the focus of the game, or the reason of victory or loss"
}
}
}
Тогда вы можете просто использовать значение после декодирования, как это
let data = jsonString.data(using: .utf8)!
// Initializes a Response object from the JSON data at the top.
let myResponse = try! JSONDecoder().decode(ChampionsData.self, from: data)
print(myResponse.tags.first?.value as Any)
Если мы использовали json, упомянутый в начале, мы получим
"you like fantacies and tricking people"