Home » Swift Compound Assignment Operators

Swift Compound Assignment Operators

by Online Tutorials Library

Compound Assignment Operators

Swift 4 provides compound assignment operators that combine assignment (=) operator with another operator. One example of compound assignment operator is the addition assignment operator (+=)

For example,

Here, a += 20 is short form for a = a + 20. Addition and assignment operators are combined into one operator that performs both tasks at the same time.

Note: The compound assignment operators don’t return a value. For example, you can’t write let b = a += 20.

You may also like