Creating Integer Instances

You created instances of Int in Chapter 2, where you learned that you can declare a type explicitly or implicitly.

Listing 4.4  Declaring Int explicitly and implicitly

...
print("The maximum value for a 32-bit unsigned integer is \(UInt32.max).")
print("The minimum value for a 32-bit unsigned integer is \(UInt32.min).")

let numberOfPages: Int = 10 // Declares the type explicitly
let numberOfChapters = 3    // Also of type Int, but inferred by the compiler

Implicit declarations with integer values are always assumed to be Int by the compiler. However, you can create instances of the other integer types using explicit type declarations.

Listing 4.5  Declaring other integer types explicitly

... let ...

Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.