SwiftのCodableでEnumを変換する
import UIKit enum Country: Int, Codable { case japan = 0 case usa case france } struct Member: Codable { let id: Int let country: Country } let json = """ { "id": 1, "country": 0 } """ let decoded = try JSONDecoder().decode(Member.self, from: json.data(using: .utf8)!) let country = decoded.country switch country { case .japan: print("日本") case .usa: print("アメリカ") case .france: print("フランス") } print(decoded.country)