In Swift 4.1 it could be achieved this way:
prefix operator ++
postfix operator ++
extension Int{
static prefix func ++(x: inout Int)->Int{
x += 1
return x
}
static postfix func ++(x: inout Int)->Int{
x += 1
return x-1
}
}
//example:
var t = 5
var s = t++
print("\(t) \(s)")
Notice that despite the fact that this solution in similar to previous solutions in this post, they don't work anymore in Swift 4.1 and this example does.
Also notice that whomever above mentions that += is a replacement for ++ just don't fully understand the operator as ++ combined with assignment is actually two operations, hence a shortcut.
In my example: var s = t++
does two things: assign the value of t to s and then increment t. If the ++ comes before, it's the same two operations done in reversed order.
To my opinion, the reasoning of Apple about why to remove this operator(mentioned in previous answers), is not only false reasoning but furthermore I believe it is a lie and the true reason is that they couldn't make their compiler handle it. It gave them troubles in previous versions so they gave up.
The logic of "too complicated to understand operator, hence removed" is obviously a lie because Swift contains operators far more complicated and much less useful which were not removed. Also, the vast majority of programming languages has it.
JavaScript, C, C#, Java, C++ and so many more. Programmers happily use it.
Whomever it is too difficult to understand this operator for, they and only they should do the += (or perhaps s = s + 1 if += is too complexed as well).
The strategy behind Swift is simple: Apple believes the programmer is dumb and therefore should be treated accordingly.
The truth is that Swift, launched at September 2014 was supposed to be somewhere else by now. Other languages grew up much faster.
I can list many major mistakes in the language, from serious ones: such as arrays pasted by value and not by reference, to annoying ones: variadic parameters functions can't accept an array which is the whole idea behind it.
I don't think that Apple's employees are even allowed to look at other languages such as Java so they don't even know that Apple is light years behind. Apple could have adopted Java as a language but these days, challenge is not technology, but ego is.
If they would have opened IntelliJ to write some Java, they would for sure close their business understanding that at this point, they can't and won't catch up ever.