I am facing a challenge regarding mapping a generic api responses against a model class using codable or object mapper. Suppose I have these api responses against different apis.
{
"code" : 0,
"http_response" : 200,
"success" : true,
"data" : user
}
{
"code" : 0,
"http_response" : 200,
"success" : true,
"data" : locations
}
{
"code" : 0,
"http_response" : 200,
"success" : true,
"data" : countries
}
here user, locations and countries are separate codable/mapper classes.
I will have to construct a class like this
struct APIResponse : Codable {
let success : Bool?
let http_response : Int?
let code : Int?
let data : ??
}
How I will construct my base class to handle these responses using one class or I will have construct different classes just to change "data" type according to value?
Any kind of help or suggestion will be highly appreciated.
Thanks