On 64-bit platforms, Int
is the same size as Int64
, and on 32-bit platforms, Int
is the same size as Int32
.
Can this behavior be changed, i.e. can Int
's size be forced to be Int32
on 64-bit platforms?
On 64-bit platforms, Int
is the same size as Int64
, and on 32-bit platforms, Int
is the same size as Int32
.
Can this behavior be changed, i.e. can Int
's size be forced to be Int32
on 64-bit platforms?
The idea behind Int
is that it reflects the native size (32-bit on 32-bit system and 64-bit on 64-bit system).
If you really want a 32-bit int no matter what platform you're on then you use Int32
.
If you really want a 64-bit int no matter what platform you're on then you use Int64
.
To solve your problem be explicit and just use Int32
instead of Int
.
There are multiple data types available in Swift to define an integer
- Int, Int8, Int16, Int32, Int64
- UInt, UInt8, UInt16, UInt32, UInt64
You can use any of the above as per your requirement independent of whether you're using a 32-bit or 64-bit platform.