Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float parsing error #113

Open
Przemyslaw-Wosko opened this issue Jun 8, 2017 · 4 comments
Open

Float parsing error #113

Przemyslaw-Wosko opened this issue Jun 8, 2017 · 4 comments

Comments

@Przemyslaw-Wosko
Copy link

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
Copy link
Author

@jarsen ? Anyone?

@zierka
Copy link

zierka commented Jun 25, 2017

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

@MoseDien
Copy link

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

@daniel3223
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants