++ is deprecated it will be removed in swift 3 [closed]

Rewrite it as:

variable += 1

…exactly as the warning message suggests. This will now need to be a separate line, of course (that’s the only bad thing about this change). What matters is where you put that line.


So for example

let otherVariable = ++variable // variable is a previously defined var

now becomes

variable += 1 // variable is _still_ a previously defined var
let otherVariable = variable

But on the other hand

let otherVariable = variable++ // variable is a previously defined var

now becomes

let otherVariable = variable
variable += 1 // variable is _still_ a previously defined var

Extra for experts: In the rare situation where you return variable++ — that is, you return variable, which is in a higher scope, and then increment it — you can solve the problem like this:

defer {
    variable += 1
}
return variable

Leave a Comment