I know the basic concept of class
and struct
but which is more effective to create models for API to fetch data and tell me with pros and cons.
Previously i don't use optional for models. Instead i give it some value. ie
class CompanyInfo : Codable {
var NameEn : String = ""
var CityEn : String = ""
var Website : String = ""
var Email : String = ""
var Phone : String = ""
var Fax : String = ""
}
but when it get some null
value from API. ie "Fax": null
then App get crashed because it can't parse data with following line
let data = try JSONDecoder().decode(dataModel.self, from: dataSet)
what is the best way to deffine a model so i don't need to unwrap optional or give it default value.