[英]Swift: Get double value from 'index' in enumeration
In a simple Swift enumeration like this: 在一个简单的Swift枚举中,如下所示:
for (index, value) in enumerate(array) {
let indexValue = idx as NSNumber
let double = indexValue.doubleValue
.... }
is there an easier way to convert the 'index' value to a double? 有没有更简单的方法可以将“索引”值转换为双精度值?
Yes there is: 就在这里:
for (index, value) in enumerate(array) {
let doubleVal = Double(index)
}
The number types in Swift generally have an init method that takes any of the other number types. Swift中的数字类型通常具有采用其他任何数字类型的init方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.