Chapter    13

Assignment Operators

When you want to initialize or update a value, you use the assignment operator (=). You saw this already when you learned to declare constants and variables with a value using the assignment operator (see Listing 13-1).

Listing 13-1. Declaring and Assigning Values

//Assigning a variable valuevar a = 1//Assigning a constant valuelet b = 2

You can update the variable values at any time after the variable has been declared using the assignment operator (see Listing 13-2).

Listing 13-2. Updating Values

a = 3

Of course, you cannot do this with a constant.

You can assign multiple values to multiple variables or constants on the same line to save space (see Listing 13-3).

Listing 13-3. Multiple Assignments

let (c, ...

Get Swift Quick Syntax Reference 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.