Integer Types and Their Ranges
Understand Int, UInt, Int8..Int64 and their bounds.
Integer Types in Swift
Swift has several integer types. Int is the default and matches the platform word size (usually 64-bit). There are also fixed-width types like Int8, Int16, Int32, and Int64.
let count: Int = 42
print(count)
print(type(of: count))Signed vs Unsigned
Signed types (Int) can hold negative and positive values. Unsigned types (UInt) hold only zero and positive values, gaining a larger positive range.
let signed: Int = -10
let unsigned: UInt = 10
print(signed, unsigned)All lessons in this course
- Integer Types and Their Ranges
- Floating-Point: Double vs Float
- Explicit Numeric Conversions
- Numeric Literals and Underscores