我正在将我们的代码库迁移到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.
关于这里发生了什么的任何想法?我该如何解决这个问题?