I have the following struct, and try to decode the object as follows.
I am using Swift 4.3.
struct Classroom: Codable {
let teacher: Teacher
let id: Int
let status: String?
}
let classes: Classroom = try clasroom.decodeObject()
However, status
object has two different types either String
or Dictionary
. If it comes as a Dictionary
, then I am only interested to assign the key
to the status
.
it works in the following case,
{"teacher": {"name": "Carolina"},"id": 20,"status": "Success"}
Wondering how to handle these type of scenarios?
{"id": 20, "teacher": {"name": "Carolina"},"status":{"Failure":"network is down"}}