I am making a request to an API which is returning either an Int or String value for the variable of interest milesDriven. Here is the model which parses the response:
struct RandomTypes: Codable {
var milesDriven: String?
var other: String?
var fromDate: String?
var toDate: String?
var type: String?
var displayType: String?
}
I obviously get an error if milesDriven is an Int; so naturally I tried to use Any? as the response type. However, RandomTypes does not conform to the Codable protocol if I use Any?.
How can I accept either a String or an Int while still conforming to the Codable protocol?