Multiple increments in Swift style for loops

Viewed 13568

I have the following loop in my Swift code:

for var i:Int = 0, j:Int = 0; i < rawDataOut.count; i += 4, ++j {
    maskPixels[j] = rawDataOut[i + 3]
}

I'm getting two warnings in Xcode:

  1. C-style for statement is deprecated and will be removed in a future version of Swift
  2. '++' is deprecated: it will be removed in Swift 3

I cannot see how to rewrite this in Swift's For In Loops to take into account the two variables and the 4-stride without it getting messy. Is there a simple elegant translation?

2 Answers

In Swift 4

for index in stride(from: 0, to: 10, by: 2){
    print(index)
}
Related