0

I'm parsing json object with Id (long) coming from a Java backend. the id is declared as CLong in my app. On iPhones5 < it works, but on iPhone5 the id is invalid value.

SpyZip
  • 5,511
  • 4
  • 32
  • 53

1 Answers1

1

CLong is a typedef for Int in the iOS SDK:

/// The C 'long' type.
public typealias CLong = Int

From the Swift docs:

  • On a 32-bit platform, Int is the same size as Int32.
  • On a 64-bit platform, Int is the same size as Int64.

Unless you need to work with a specific size of integer, always use Int for integer values in your code. This aids code consistency and interoperability. Even on 32-bit platforms, Int can store any value between -2,147,483,648 and 2,147,483,647, and is large enough for many integer ranges.

If you need to keep your Integer size consistent across multiple architectures, use Int32. If you value is larger than 32 bits, you should look into handling overflows. Also consider sending a different data type rather than a long from your backend, such as a String or NSNumber.

Community
  • 1
  • 1
JAL
  • 41,701
  • 23
  • 172
  • 300