Integers

Most of the time, you will use Int for all integers. Apple's advice is to use Int for all cases except where you need to work with a specific size of integer. Similarly, Int should be preferred to UInt even for values that cannot be negative, unless you need an unsigned integer type of the same size as the platform's native word size.

If you're not sure what that means, don't worry about it; just use Int.

The following table shows all the integer types available in Swift, along with their maximum and minimum values (unsigned minima are, of course, 0):

Integer Type

Value

Int.min

-9223372036854775808

Int.max

9223372036854775807

Int8.min

-128

Int8.max

127

Int16.min

-32768

Int16.max

32767

Get Mastering macOS Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.