-2

How do I change the code since C style for statement is deprecated in swift 3? I am getting an error on the following line of code:

for var frame = 0; frame <= frameCount; frame += 1

func keyframePathsWithDuration(_ duration: CGFloat, lastUpdatedAngle: CGFloat, newAngle: CGFloat, radius: CGFloat, type: RMIndicatorType) -> [CGPath] {
    let frameCount: Int = Int(ceil(duration * 60))
    var array: [CGPath] = []
    for var frame = 0; frame <= frameCount; frame += 1 {
        let startAngle = degreeToRadian(-90)

        let angleChange = ((newAngle - lastUpdatedAngle) * CGFloat(frame))
        let endAngle = lastUpdatedAngle + (angleChange / CGFloat(frameCount))
        array.append((self.pathWithStartAngle(startAngle, endAngle: endAngle, radius: radius, type: type).cgPath))
    }
    return array
}
Bista
  • 7,869
  • 3
  • 27
  • 55

1 Answers1

1

Try this new syntax of Swift 3/4

func keyframePathsWithDuration(_ duration: CGFloat, lastUpdatedAngle: CGFloat, newAngle: CGFloat, radius: CGFloat, type: RMIndicatorType) -> [CGPath] {
            let frameCount: Int = Int(ceil(duration * 60))
            var array: [CGPath] = []
            for frame in 0...frameCount {
                let startAngle = degreeToRadian(-90)

                let angleChange = ((newAngle - lastUpdatedAngle) * CGFloat(index))
                let endAngle = lastUpdatedAngle + (angleChange / CGFloat(frameCount))
                array.append((self.pathWithStartAngle(startAngle, endAngle: endAngle, radius: radius, type: type).cgPath))
            }
            return array
}

and for more information about the new loop syntax is :

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html

Ronak Adeshara
  • 321
  • 4
  • 13