Swift 3:用float增量replacec样式for循环

我在我的应用程序中有这样一个循环:

for var hue = minHue; hue <= maxHue; hue += hueIncrement { let randomizedHue = UIColor.clipHue( Random.uniform(ClosedInterval(hue - dispersion, hue + dispersion)) ) colors.append(colorWithHue(randomizedHue)) } 

hueIncrement浮动的 ,所以我不能使用范围运算符像这样: ..<

在Swift 3中实现这种循环的最好和最简单的方法是什么?

你可以使用跨步functionstride(through:, by:) ,由此..类似的东西

 for hue in (minHue).stride(through: maxHue, by: hueIncrement){ // ... } 

Swift3.0 ,你可以使用stride(from:to:by:)或者stride(from:through:by:)语法

 for hue in stride(from: minHue, through: maxHue, by: hueIncrement){ //.... }