++ and — operators

Deep Arora
Apr 6, 2021
Photo by Fotis Fotopoulos on Unsplash

Many programming languages have increment and decrement operators as:

pre-increment - returns input value after mutation
post-increment - returns value before mutation
pre-decrement - returns input value after mutation
post-decrement - returns value before mutation

To your surprise, these operators are not part of Swift programming language since Swift 3.0. More detail on why these operators are removed can be found here: https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md

However, if you had the habit of using these from other languages, you may find them convenient to use in Swift. Generic implementation of these operators:

Output:

11
11.0

--

--