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){ //.... }
- Firebase云消息传递不会创build推送通知,但会获取信息
- 更新到Xcode 8后的错误:“没有这样的模块”和“目标覆盖EMBEDDED_CONTENT_CONTAINS_SWIFT”build立设置“
- 在没有互联网连接的情况下,从数据库使用iOS应用程序中
- 如何在Swift中实现didReceiveMemoryWarning?
- Swift coreData – 格式化date并在谓词中使用它
- 无法在Xcode中连接IBAction
- Firebaseasynchronousfunction,后台队列中有什么,什么不是
- 实况video如何从iOS设备stream式传输到服务器?
- 如何“在谷歌地图上显示我当前的位置,当我打开ViewController?”在Swift?