我在SwiftMoment的这部分代码中遇到了这个问题https://github.com/akosma/SwiftMoment
public func moment(_ timetoken: Int64) -> Moment {
return moment(Int(timetoken / 10000))
}
我不确定为什么会这样 . 如果您有任何见解,请随时分享 . 谢谢!
这是timetoken值: timetoken 14915504189961350
它发生在Simulator MacOS Sierra 10.12.4上
Xcode 8.3.1 iOS 10.3.1 iPhone 5
更新
这个问题没有出现在iPhone 7上
1 回答
iPhone 5是一个32位设备,这意味着Int is a 32-bit integer,
timetoken / 10000
的结果不适合Int
. 与其他一些编程语言相比,整数溢出是Swift中的致命运行时错误(这很好,因为否则你会得到错误的结果) .我建议将值转换为
TimeInterval
(这是一个浮点类型,实际上只是Double
的类型别名)然后调用代替