Numeric types
Swift contains many of the standard numeric types that are suitable for storing various integer and floating-point values.
Integers
An integer is a whole number. Integers can be either signed (positive, negative, or zero) or unsigned (positive or zero). Swift provides several integer types of different sizes. The following chart shows the value ranges for the different Integer types:
Type |
Minimum |
Maximum |
---|---|---|
|
-128 |
127 |
|
-32,768 |
32,767 |
|
-2,147,483,648 |
2,147,483,647 |
|
- 9,223,372,036,854,775,808 |
9,223,372,036,854,775,807 |
|
- 9,223,372,036,854,775,808 |
9,223,372,036,854,775,807 |
|
0 |
255 |
|
0 |
65,535 |
|
0 |
4,294,967,295 |
|
0 |
18,446,744,073,709,551,615 |
|
0 |
18,446,744,073,709,551,615 |
Tip
Unless there is a specific reason to define the size of an integer, I would recommend using the standard Int
or UInt
type. This will save you from needing to convert between different types of integers.
In Swift, Int
(as well as other numerical...