O'Reilly logo

Swift 3 ObjectOriented Programming - Second Edition by Gastón C. Hillar

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

Declaring compound assignment operator functions

We also want to be able to increase the value of the age property of the different Animal instances by using the addition assignment operator (+=). This operator is one of the compound assignment operators that Swift provides and it combines assignment (=) with the addition operator (+).

Tip

Swift 3 removed both the pre-increment, post-increment, pre-decrement, and post-decrement operators. In other words, we cannot use ++ and -- in Swift 3. We might define a prefix increment and a postfix increment to increase the value of the age property, but it doesn't make sense to define an operator that Swift 3 has removed. Instead, we will use the addition assignment operator.

We have to declare an operator ...

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