Swift中Int和Int32有什么区别? [英] What is the difference between Int and Int32 in Swift?

查看:1457
本文介绍了Swift中Int和Int32有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

核心数据中,您可以存储 Int16 Int32 Int64 但它与 Int 不同。它们存在的原因是什么,你如何使用它们?

In Core Data you can store Int16, Int32, Int64 but it is different from Int. What is the reason for their existence, how do you use them?

推荐答案

根据 Swift文档


Int



在大多数情况下,您无需选择要在代码中使用的特定大小的整数。 Swift提供了一个额外的整数类型Int,它与当前平台的本机字大小相同:

Int

In most cases, you don’t need to pick a specific size of integer to use in your code. Swift provides an additional integer type, Int, which has the same size as the current platform’s native word size:

在32位平台上,Int是与Int32相同的大小。

在64位平台上,Int与Int64的大小相同。

除非您需要使用特定大小的整数,否则请始终在代码中使用Int作为整数值。这有助于代码一致性和互操作性。即使在32位平台上,Int也可以存储-2,147,483,648和2,147,483,647之间的任何值,并且对于许多整数范围来说足够大。

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.

这篇关于Swift中Int和Int32有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆