I've been updating my Swift code for Swift 3 (really excited) and so far so good. But I did tumble accros one little bit of code I can't seem to update.
I KNOW I am missing something very simple, but I just can't see what.
Here is what I have in Swift 2.2:
var column = 0
[...]
for item in 0 ..< collectionView!.numberOfItemsInSection(0) {
[...]
column = column >= (numberOfColumns - 1) ? 0 : ++column
}
The ++column
is of course being deprecated in Swift 3 in favor of column += 1
However, in THIS context, it produces an error:
No '+=' candidates produce the expected contextual result type 'Int'
Since this line of code (column = column >= (numberOfColumns - 1) ? 0 : column += 1
) produces an error, I tried the following:
var newCol = column
column = column >= (numberOfColumns - 1) ? 0 : newCol += 1
But I get the same error.
Could someone point me in the correct direction?
+=
does not return a value. You need to break this out. Luckily in your case that's straightforward and clearer than the original:
column = (column + 1) % numberOfColumns
Like this:
column = column >= (numberOfColumns - 1) ? 0 : column + 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With