tristanhimmelman / AlamofireObjectMapper

An Alamofire extension which converts JSON response data into swift objects using ObjectMapper
MIT License
2.66k stars 474 forks source link

Parsing a Float error #242

Closed quetool closed 5 years ago

quetool commented 6 years ago

Hi, I was using a mappable model like this

struct BalanceData: Mappable {

    var balance = Float()

    init?(map: Map){
    }

    mutating func mapping(map: Map) {
        balance     <- map["balance"]
    }

}

And this is the response I am parsing into that model

{
  "status": 200,
  "message": "OK",
  "error": "",
  "data": {
    "balance": 797.76
  }
}

This was working just great until I update to Xcode 9.3 and macOS High Sierra this morning. Now BalanceData.balance is getting 0 instead of 797.76, I have to change var balance = Float() to Double() in model in order to get the correct value.

alexpersian commented 6 years ago

Seeing this same issue with our models after moving to Xcode 9.3 (Swift 4.1). I've been able to verify that the processing works fine on Xcode 9.2 (Swift 4.0.3).

We have data from the network coming in as follows:

1 : 2 elements
  - key : "someCoordinateX"
  - value : 94.3

Doing the follow operations results in different values based on the Xcode version the project is compiled with.

var someCoordinateX: Float?

map[kSomeCoordinateXKey].currentValue       // this shows 94.3

// Xcode 9.2
someCoordinateX <- map[kSomeCoordinateXKey] // this shows 94.3

// Xcode 9.3
someCoordinateX <- map[kSomeCoordinateXKey] // this shows nil

This is with ObjectMapper v. 5.0.0

Edit: Like above, this is resolved by switching from Float to Double.

Edit2: This looks to be rooted in an ObjectMapper issue. https://github.com/Hearst-DD/ObjectMapper/issues/954

michael-mckenna commented 6 years ago

I can confirm this issue as well. It won't map longitude and latitude for one of our models.

mattsellars commented 6 years ago

fwiw I ran into a similar issue and noticed it doesn't happen for me when running on iOS 11 sim but does on iOS 10 sim (when running in Xcode 9.3)

wemped commented 6 years ago

Looks like there has been an update to fix this in this ObjectMapper release https://github.com/Hearst-DD/ObjectMapper/releases/tag/3.2.0

I would assume we just need an update to this project to point to that release