I've been careful to declare variables with "Int64 for integers whose values can be big, Int for integers that don't", but depending on the execution environment, such consideration is unnecessary. , Is the story.
Prerequisite environment for this article: ・ IOS 11 or later ・ Swift 5
As a background to the consideration at the beginning, This is because the maximum and minimum values of Int have the characteristic that ** "the execution environment differs depending on whether it is 32bit or 64bit", and the range is narrow if it is 32bit **.
Type | Maximum value | minimum value |
---|---|---|
Int | 2147483647 9223372036854775807 |
-2147483648 -9223372036854775808 (Execution environment depends on 32bit or 64bit) |
Int64 | 9223372036854775807 | -9223372036854775808 |
Quote: Unexpectedly unknown Swift numeric type detailed specifications
So, in the 32-bit environment Int, for example, if the value to be handled is the amount (yen), the maximum value is 2,147 million yen, so in the case of a celebrity, the application may crash.
However, if you think about it, the app I'm currently working on can only be used on iPhones with iOS 11 or later.
After checking, it seems that ** iOS 11 or later does not have a 32-bit execution environment **.
Reference: iOS device screen size / supported OS quick reference table (iOS7-12)
That means that if the app supports only iOS 11 or later, there is no point in using Int and Int64 properly **, so the consideration at the beginning was unnecessary.
Recommended Posts