I have the following code
var column = 0
column = column >= 2 ? 0 : ++column
Since 2.2 I get a depreciation warning, any ideas how I can fix this?
I have this solution:
if column >= 2 {
column = 0
} else {
column += 1
}
But this isn't really nice.
How about:
It looks like you might be doing something like clock arithmetic. If so, this gets the point across better:
In the simplest case, you can replace
++column
withcolumn + 1
:You can also rewrite your code in an if-else statement with a
+=
operator:Moreover, although I would not recommend using it in production code, you can reimplement
++
(prefix / postfix increment operator) and--
(prefix / postfix decrement operator) for typeInt
in Swift 2.2 and Swift 3 with custom operators, in-out parameters and defer statement.As an example, the following playground code that uses ternary operator generates no warnings with Swift 2.2 and Swift 3: