I have struct like this:
struct OrderLine: Codable{
let absUrl: String?
let restApiUrl : String?
let description : String?
let quantity : Int?
let subscription: Subs?
let total: Double?
}
struct Subs: Codable{
let quantity: Int?
let name: String?
}
and some OrderLine
has in server response
"subscription": {
"quantity": 6,
"name": "3 Months"
},
but sometimes it has String
type:
"subscription": "",
without subscription
everytthing works fine, but with I've got an error
CodingKeys(stringValue: "subscription", intValue: nil)],
debugDescription: "Expected to decode Dictionary<String, Any>
but found a string/data instead.", underlyingError: nil)
so my question is - how can I decode or to String?
with value ""
, or to Subs?
without any error?
p.s. if I decode it like String?
only, then have error debugDescription: "Expected to decode String but found a dictionary instead.", underlyingError: nil)