utahiosmac / Marshal

Marshaling the typeless wild west of [String: Any]
MIT License
697 stars 62 forks source link

Float parsing error #113

Open Przemyslaw-Wosko opened 7 years ago

Przemyslaw-Wosko commented 7 years ago

Hi, I have troubles with parsing simple values, like Float,

i wrote simple test:

{
    "floatArray": [9.123, 0.000001, 0.1, -2]
}
func testParseFloatArray() {
        guard let path = Bundle(for: type(of: self)).path(forResource: "FloatArray", ofType: "json"),
            let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
            let json = try? JSONParser.JSONObjectWithData(data) else {
                XCTFail("Error parsing FloatArray.json")
                return
        }

        do {
            let array: [Float] = try json.value(for: "floatArray")
            XCTAssert(array.count == 5)
            XCTAssert(array[0] == 9.123)
        } catch {
            XCTFail(String(describing: error))
        }
    }

and it fails with:

▿ Type mismatch. Expected type Float for key: floatArray. Got '__NSCFNumber'
  ▿ typeMismatchWithKey : 3 elements
    - key : "floatArray"
    - expected : Swift.Float
    - actual : __NSCFNumber

Should i try to make pull request with fix for this?

Przemyslaw-Wosko commented 7 years ago

@jarsen ? Anyone?

zierka commented 7 years ago

Looks like this is a swift 4/xcode 9 issue.

MoseDien commented 7 years ago

I encounter it also, I don't know Apple will fix it before iOS11 formal release. It should be NSDecimalNumber, not NSNumber.

daniel3223 commented 6 years ago

I updated Xcode today to 9.3 with swift 4.1 and this issue happens again. Please help