相关疑难解决方法(0)

Swift 3迁移 - 双扩展舍入问题

我正在将我们的代码库迁移到Swift 3,我遇到了一个无法解释或修复的编译问题.

我在Double扩展中有一个方法,Double可以将数字舍入到一定数量的数字:

public func roundToPlaces(places: Int) -> Double {
    let divisor = pow(10.0, Double(places))
    return round(self * divisor) / divisor
}
Run Code Online (Sandbox Code Playgroud)

例如: 12.34567.roundToPlaces(2)应该返回12.35.但是,我收到round此扩展中使用的方法的编译问题.这是说我Cannot use mutating member on immutable value: 'self' is immutable.

编译错误图像

关于这里发生了什么的任何想法?我该如何解决这个问题?

double rounding swift3 xcode8

2
推荐指数
1
解决办法
1005
查看次数

标签 统计

double ×1

rounding ×1

swift3 ×1

xcode8 ×1