Book Image

Mastering Swift

By : Jon Hoffman
Book Image

Mastering Swift

By: Jon Hoffman

Overview of this book

Table of Contents (22 chapters)
Mastering Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

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

Int

- 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

UInt

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...