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 unary operator functions

As previously explained, Swift 3 removed the prefix increment and postfix increment operators. However, imagine that many members of our team have experience with other programming languages that provide these operators and they want to use them to increase the value of the age property of the different Animal instances. We can declare the following unary operators to simplify their lives while coding:

  • Prefix increment (++): We will use the operator before the variable to which it is applied (for example, ++pluto)
  • Postfix increment (++): We will use the operator after the variable to which it is applied (for example, pluto++)

In this case, both the operators use exactly the same characters; therefore, we must use ...

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