Loop - invoke 'stride' with CGFloat

336 views Asked by At

My code:

for i:CGFloat in 0.stride(through: 100, by: spaceBetweenMarkers)  

Error:

Cannot invoke 'stride' with an argument list of type '(through: CGFloat, by: CGFloat)'

How can I use for loop by using a CGFloat value? I am using Swift 3. I want to iterate from 0 to 100 and pass a CGFloat value.

1

There are 1 answers

0
user3441734 On BEST ANSWER
import Foundation

let cf0 = CGFloat(0.0)
for cf in stride(from: cf0, through: 2.0, by: 1.0) {
    print(cf, type(of: cf))
}

prints

0.0 CGFloat
1.0 CGFloat
2.0 CGFloat