Im trying to map my data which is come from backend server. But the problem is I have 2 different type one is Int and other ones are String . Im using object mapper for mapping and my code is like ;
class OptionsData : Mappable , ObservableObject {
var id = UUID()
@Published var name : String?
@Published var type : String?
@Published var typeID : String?
@Published var typeArry : [TypeItem]?
@Published var image : String?
@Published var icon : String?
@Published var platformID : String?
@Published var imageRatio : Double?
@Published var priceSell : Double?
@Published var vat : Double?
@Published var targetCurrency : String?
@Published var isDiscountActive : Double?
@Published var displayVat : Int?
required init?(map: Map) {
}
func mapping(map: Map) {
name <- map["name"]
type <- map["type"]
typeID <- map["type_id"]
typeArry <- map["type_arr"]
image <- map["image"]
icon <- map["icon"]
platformID <- map["platform_id"]
imageRatio <- map ["image_ratio"]
priceSell <- map ["price_sell"]
targetCurrency <- map["target_currency"]
vat <- map ["vat"]
isDiscountActive <- map ["is_discount_active"]
displayVat <- map ["display_vat"]
}
init(name : String? = nil , type : String? = nil , typeID : String? = nil , typeArry : [TypeItem]? = nil , image : String? = nil ,icon : String? = nil , platformID : String? = nil ,image_ratio : Double? = nil,price_sell : Double? = nil,vat : Double? = nil ,targetCurrency : String? = nil,isDiscountActive : Double? = nil,displayVat : Int? = nil) {
self.name = name
self.type = type
self.typeID = typeID
self.typeArry = typeArry
self.image = image
self.icon = icon
self.platformID = platformID
self.imageRatio = image_ratio
self.priceSell = price_sell
self.vat = vat
self.targetCurrency = targetCurrency
self.isDiscountActive = isDiscountActive
self.displayVat = displayVat
}
}
im trying to do this for typeID . is there is a way to work for 2 different type ?
question from:
https://stackoverflow.com/questions/65935802/how-to-map-for-two-different-type-with-objectmapper 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…