ios - 没有 * 候选人产生预期的结果类型 FloatingPointRoundingRule

标签 ios swift3 rounding

在 Swift 3 中我收到以下错误(这在 Swift 2 中没有发生):

No * candidates produce the expected result type FloatingPointRoundingRule

我不知道我需要做什么来修复它。

我正在尝试将纬度小数转换为度/分/秒

extension CLLocationDegrees {        
    mutating func toLatitudeSeconds() -> String {
        var seconds = Int(round(self * 3600)) //error here
        // etc ...
    }
}

最佳答案

舍入函数被更改为在实例上调用而不是全局函数。您基本上是在尝试执行 self.round(self*3600) 这不起作用,因为 round 函数不接受任何参数或类型为 的参数FloatingPointRoundingRule.

你可能想要:

var seconds = Int((self*3600).rounded())

关于ios - 没有 * 候选人产生预期的结果类型 FloatingPointRoundingRule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39621668/

相关文章:

c# - 将 DateTime 舍入为 30 分钟时处理没有分钟的小时

ios - UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName 不起作用

ios - 使用 iPhone GPS 运行时获得最准确的 "current pace"

swift - Bool 未正确返回

ios - 无法转换 LazyMapRandomAccessCollection 类型的值

python - 如何在 Python 中使数字更精确?

python - 查找范围内的圆间隔

ios - 当 AVPlayer 在 exportAsynchronouslyWithCompletionHandler 中创建时,在看到视频之前有很长的延迟

ios - 全局变量神秘丢失内存?

ios - 在应用程序设置页面中更改通知的用户权限时更新 UILabel 文本值?