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

Get Swift 3 ObjectOriented Programming - 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.