Numerical Data Types
Explore Swift data types in detail and learn about the numerical types supported by Swift. Additionally, use Boolean variables to store true and false values.
We'll cover the following
Now that we have a basic understanding of the concept of data types and why they are necessary, we can take a closer look at some of the more commonly used data types supported by Swift, starting with numerical data types.
Integer data types
Swift integer data types are used to store whole numbers (in other words a number with no decimal places). Integers can be signed (capable of storing positive, negative, and zero values) or unsigned (positive and zero values only).
Swift provides support for 8, 16, 32, and 64-bit integers (represented by the Int8
, Int16
, Int32
, and Int64
types, respectively). The same variants are also available for unsigned integers (UInt8
, UInt16
, UInt32
, and UInt64
).
All integer data types have bound properties that can be accessed to identify the minimum and maximum supported values of that particular type. The following code, for example, outputs the minimum and maximum bounds for the 32-bit signed integer data type:
Get hands-on with 1400+ tech skills courses.