I have been using codable in Swift from a long time and it has almost solved all the issues I had until I encountered the below mentioned issue. Suppose, the data coming from the API is something like this:
{
"name": "ABC",
"contactNo": "123",
"gender": "M",
"dob": "02-01-1998",
"qualitifcation": "XYZ"
}
Now, I want to parse some part of this data in One model and some part in another model and have the reference of another model in the first model. For Eg:
struct ModelOne: Codable {
let name: String?
let contactNo: String?
let modelTwoRef: ModelTwo?
}
struct ModelTwo: Codable {
let gender: String?
let dob: String?
let qualification: String?
}
I am not able to solve this problem. It would be really helpful is someone can help with the same.
ModelOneshould do the job.