简体   繁体   English

如何在<iPhone5和Swift中使用long值

[英]How to use long value in < iPhone5 and swift

I'm parsing json object with Id (long) coming from a Java backend. 我正在使用来自Java后端的ID(long)解析json对象。 the id is declared as CLong in my app. 该ID在我的应用中声明为CLong。 On iPhones5 < it works, but on iPhone5 the id is invalid value. 在iPhones5 <上可以使用,但是在iPhone5上,id为无效值。

CLong is a typedef for Int in the iOS SDK: CLong是iOS SDK中Inttypedef

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

From the Swift docs : Swift文档

  • On a 32-bit platform, Int is the same size as Int32. 在32位平台上,Int与Int32相同。
  • On a 64-bit platform, Int is the same size as Int64. 在64位平台上,Int与Int64相同。

Unless you need to work with a specific size of integer, always use Int for integer values in your code. 除非您需要使用特定大小的整数,否则在代码中始终将Int用作整数值。 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. 即使在32位平台上,Int也可以存储-2,147,483,648和2,147,483,647之间的任何值,并且对于许多整数范围而言足够大。

If you need to keep your Integer size consistent across multiple architectures, use Int32 . 如果需要在多个体系结构之间保持Integer大小一致,请使用Int32 If you value is larger than 32 bits, you should look into handling overflows . 如果值大于32位,则应考虑处理溢出 Also consider sending a different data type rather than a long from your backend, such as a String or NSNumber . 还可以考虑从后端发送其他数据类型,而不是发送长数据类型,例如StringNSNumber

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM