So I am trying to call backend api to get an object of type horse, I get the object in data but when I try to decode it, it does not work. How can I fix that? You can see my Mes
according to your JSON - "type":"GET_HORSE"
- you should change enum MessageType : Int,Decodable
to enum MessageType: String, Decodable
. I've checked your code after changes to a String
and got correct model here
if let json = try? decoder.decode(Message.self, from: data!) {
print(json)
print("something")
}
but it's not json
, it's a model with Message
type