O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required