HomeiOS Developmentios - ObjectMapper Int and Double returns zero at all times

ios – ObjectMapper Int and Double returns zero at all times


Utilizing Alamofire to name API returning json response with ObjectMapper to map in line with their documentation discovered on github https://github.com/tristanhimmelman/ObjectMapper I can use Double and Int as like String nevertheless it really works for String aside from Int and Double it returns zero as a worth

import Basis
import ObjectMapper

class HomeFeaturedOfferVM {
    
    static var occasion: HomeFeaturedOfferVM?
    static var homeFeaturedOfferData: HomeOfferM?
    static var HomeFeaturedOfferList: [OfferPrdouctM]?
    static var standing: Int?
    static var message: String?
    static var firstImage:String?
    static var timeData: [String] = []
    
    static func sharedInstance() -> HomeFeaturedOfferVM {
        if occasion == nil {
            occasion = HomeFeaturedOfferVM()
            return occasion!
        } else {
            return occasion!
        }
    }
    
    /// utilizing GET
    func getHomeFeaturedOffers(success: @escaping(_ successObject:AnyObject)->Void, failure: @escaping( _ failureObject: AnyObject)->Void) {
        let url = WebServices.getFeaturedOffers
        LeimoNetworkManager().GET(urlString: url,showLoader: true, success: { (successObject) in
            // right here we are going to set the response json knowledge in to the mannequin
            HomeFeaturedOfferVM.homeFeaturedOfferData = Mapper<HomeOfferM>().map(JSONObject: successObject)
            HomeFeaturedOfferVM.HomeFeaturedOfferList = HomeFeaturedOfferVM.homeFeaturedOfferData?.offersPrdoucts
            HomeFeaturedOfferVM.standing = HomeFeaturedOfferVM.homeFeaturedOfferData?.apiStatus
            HomeFeaturedOfferVM.message =
                HomeFeaturedOfferVM.homeFeaturedOfferData?.message
            
            for time in  HomeFeaturedOfferVM.HomeFeaturedOfferList ?? [] {
                HomeFeaturedOfferVM.timeData.append(time.offersPrdouctEndDate ?? "")
            }


            success(HomeFeaturedOfferVM.homeFeaturedOfferData as AnyObject)
            
        }) { (failureObject) in
            failure (StaticString.SomeError as AnyObject)
            print(failureObject as Any)
        }
    }
}

Within the Mannequin

import Basis
import ObjectMapper


class HomeOfferM: Mappable {
    required init?(map: Map) {}
    
    var standing: String?
    var message: String?
    var apiStatus: Int?
    var offersPrdoucts: [OfferPrdouctM]?
    
    func mapping(map: Map) {
        
        standing <- map["status"]
        message <- map["message"]
        apiStatus <- map["api_status"]
        offersPrdoucts <- map["featured_offers"]
    }
}

//  ---------------------------------------- this OfferPrdouctM mannequin ----------------------------------------

class OfferPrdouctM: Mappable {
    required init?(map: Map) {}

    var offerPrdouctId: Int?
    var offersPrdouctFitcherImage: [OffersPrdouctFitcherImageM]?
    var offersPrdouctName: String?
    var offersPrdouctImages: [OffersPrdouctImagesM]?
    var offersPrdouctVideos: [OffersPrdouctVideosM]?
    var offersPrdouctInstruction: String?
    var offersPrdouctEndDate: String?
    var offersPrdouctInStock: String?
    var offersPrdouctShowReview: Int?
    var offersPrdouctQuantity: Int?
    var offersPrdouctSoldQts: Int?
    var offersPrdouctPrice: Double!
    var offersPrdouctDiscountPrice: Double?
    var offersPrdouctValidityDate: String?
    var offersPrdouctTax: Double?
    var offersPrdouctTotal: Double?
    var offersPrdouctShortDescription: String?
    var offersPrdouctDescriptionT: String?
    var offersPrdouctTags: [OffersPrdouctTagsM]?
    var offersPrdouctRate: Int?
    var offersPrdouctOptions: [OfferPrdouctOptionM]?
    var offersPrdouctBranchs: [OfferPrdouctBranchM]?
    var offersPrdouctCategories: [OffersPrdouctCategoryM]?
    var offersPrdouctReview: [OffersPrdouctReviewM]?
    var offersPrdouctRelatedProducts: [OfferPrdouctM]?
    var offersPrdouctVendor: OffersPrdouctVendorM?
    var offersPrdouctCountry: OffersPrdouctCountryM?
    var offersPrdouctGovernate: OffersPrdouctGovernateM?
    var offersPrdouctArea: OffersPrdouctAreaM?
    
    func mapping(map: Map) {
        
        offerPrdouctId <- map["id"]
        offersPrdouctFitcherImage <- map["Featured_images"]
        offersPrdouctName <- map["name"]
        offersPrdouctImages <- map["images"]
        offersPrdouctVideos <- map["videos"]
        offersPrdouctInstruction <- map["instruction"]
        offersPrdouctEndDate <- map["end_date"]
        offersPrdouctInStock <- map["in_stock"]
        offersPrdouctShowReview <- map["show_review"]
        offersPrdouctQuantity <- map["quantity"]
        offersPrdouctSoldQts <- map["sold_qts"]
        offersPrdouctPrice <- map["price"]
        offersPrdouctDiscountPrice <- map["discount_price"]
        offersPrdouctValidityDate <- map["validity_date"]
        offersPrdouctTax <- map["tax"]
        offersPrdouctTotal <- map["total"]
        offersPrdouctShortDescription <- map["short_description"]
        offersPrdouctDescriptionT <- map["description_t"]
        offersPrdouctTags <- map["tags"]
        offersPrdouctRate <- map["rate"]
        offersPrdouctOptions <- map["options"]
        offersPrdouctBranchs <- map["branchs"]
        offersPrdouctCategories <- map["categories"]
        offersPrdouctReview <- map["review"]
        offersPrdouctRelatedProducts <- map["relatedProducts"]
        offersPrdouctVendor <- map["vendor"]
        offersPrdouctCountry <- map["country"]
        offersPrdouctGovernate <- map["governate"]
        offersPrdouctArea <- map["area"]
        
    }
}

Within the View Controller

print("the supply ID", HomeFeaturedOfferVM.HomeFeaturedOfferList?[indexPath.row].offerPrdouctId ?? "1" )
print("the supply Qty", HomeFeaturedOfferVM.HomeFeaturedOfferList?[indexPath.row].offersPrdouctQuantity ?? 0.0 )
print("the supply worth", HomeFeaturedOfferVM.HomeFeaturedOfferList?[indexPath.row].offersPrdouctPrice ?? 0.0 )
print("the supply Dprice", HomeFeaturedOfferVM.HomeFeaturedOfferList?[indexPath.row].offersPrdouctDiscountPrice ?? 0.0 )
print("the supply rrate", HomeFeaturedOfferVM.HomeFeaturedOfferList?[indexPath.row].offersPrdouctRate ?? 0.0 )

Values are zero at all times.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments