我有下面的代码将值四舍五入到任何最接近的数字:调用具有相同名称为自定义功能的内置函数
func round(_ value: Double, toNearest nearest: Double) -> Double {
let roundedValue = round(value/nearest) * nearest
return roundedValue
}
不过,我得到以下投诉,因为我用的是相同的这个方法的名称为内置的:
Missing argument for parameter 'toNearest' in call
有没有办法解决这个问题?即builtin round(value/nearest)
?
谢谢。
您是否尝试过'Darwin.round(价值/最近)'? – OOPer
供参考具有通过其签名进行区分的具有相同名称的多个函数称为函数重载。 – Balanced
相关:[Swift 3.0:调用全局func min(T,T)时数组或字典扩展中的编译器错误](https://stackoverflow.com/q/39602298/2976878)&[Xcode 8 Beta 4 Swift 3 - “圆”行为改变](https://stackoverflow.com/q/38767635/2976878) –
Hamish