Chapter    4

Constants, Variables, and Data Types

In OOP languages, an immutable object is an object whose state can’t be modified. Swift calls these constants. Once a constant object has been created and an initial value has been assigned, the object cannot be changed. In contrast, an object whose value can be changed is a mutable object, or the object can be mutated. Swift calls these objects variables.

In Swift, when defining variables they must be initialized with a valid value before they can be used. Use the var keyword to define a mutable object and the let keyword to define an immutable object. Note that all types can be defined either as mutable or immutable (constant or variable) based on whether they’re defined with let or var keyword. ...

Get Learn Swift 2 on the Mac, Second Edition 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.