Search code examples
iosswiftapple-watch

JSONDecoder can't decode on real device when it runs fine on simulator


I have a JSONDecoder that works on simulator, but it can't decode the same data when running on real device, please help. This error will happen when running on real device:

dataCorrupted(Swift.DecodingError.Context(
  codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), 
  CodingKeys(stringValue: "market_cap", intValue: nil)], 
  debugDescription: "Parsed JSON number <16541228553> does not fit in Int.", 
  underlyingError: nil))

I think 16541228553 should fit in Int? It fits when running on simulator. Thanks.


Solution

  • You note in the tags that this is an Apple Watch. I'm guessing it's a Series 3, which is a 32-bit platform. This is a 34-bit number, so it doesn't fit.

    The Simulator does not emulate hardware. It's a 64-bit Mac app that links libraries that match the device SDK. So on Simulator, it doesn't overflow.