iOS Developer Library — Pre-Release

Developer

Swift Standard Library Reference

PDF
On This Page

Numeric Types

The Swift standard library contains many standard numeric types, suitable for storing various integer and floating-point values. The Swift standard library also contains a single Boolean type to store Boolean values.

Integer Types

As shown in the table below, the Swift standard library provides types for signed and unsigned integers in 8, 16, 32, and 64 bit forms. The standard library also provides two types of native word-sized integers: Int for signed integers and UInt for unsigned integers. For example, Int holds 32 bits on 32-bit platforms and 64 bits on a 64-bit platform. Similarly, UInt holds 32 bits on 32-bit platforms and 64 bits on a 64-bit platform.

The default inferred type of an integer literal is Int:

  • let intValue = 42
  • // intValue is of type Int

You should use the word-sized Int type to store integer values, unless you require a type with a specific size or signedness.

Type

Minimum Value

Maximum Value

Int8

-128

127

Int16

-32,768

32,767

Int32

-2,147,483,648

2,147,483,647

Int64

-9,223,372,036,854,775,808

9,223,372,036,854,775,807

UInt8

0

255

UInt16

0

65,535

UInt32

0

4,294,967,295

UInt64

0

18,446,744,073,709,551,615

Floating Point Types

The Swift standard library provides three signed floating-point number types: Float for 32-bit floating-point numbers, Double for 64-bit floating point numbers, and Float80 for extended-precision 80-bit floating-point numbers.

The default inferred type of a floating-point literal is Double:

  • let floatingPointValue = -273.15
  • // floatingPointValue is of type Double

Boolean Type

The Swift standard library provides one Boolean type, Bool. Bool is a value type whose instances are either true or false.