2017-04-10 73 views
3

我與SwiftMoment 遇到這個問題,在這部分代碼https://github.com/akosma/SwiftMomentEXC_BAD_INSTRUCTION(代碼= EXC_I386_INVOP,子碼=爲0x0)上迅速

public func moment(_ timetoken: Int64) -> Moment { 
    return moment(Int(timetoken/10000)) 
} 

我不知道爲什麼它happenning。如果您有任何見解,請隨時分享。 謝謝!

enter image description here

這裏是timetoken值: timetoken 14915504189961350

它發生在模擬器 MacOS的塞拉利昂10.12.4

的Xcode 8.3.1 的iOS 10.3.1 iPhone 5

更新

問題犯規出現在iPhone 7

+1

public func moment(_ seconds: TimeInterval) -> Moment 

代替你有完整的堆棧跟蹤嗎? – kennytm

+0

我有點新xcode。我已添加更多信息。我如何分享完整的堆棧跟蹤? –

+0

'timetoken'的價值是什麼?錯誤發生在哪裏? Mac/iOS設備/模擬器? 32位或64位平臺? –

回答

3

的iPhone 5是一個32位的裝置,這意味着Int is a 32-bit integer,和timetoken/10000結果不適合放入一個 Int。與其他一些編程語言相比,整數溢出在Swift中是致命的運行時錯誤(這很好,因爲否則 你只會得到錯誤的結果)。

我會建議值轉換爲TimeInterval,而不是 (這是一個浮點類型,實際上只是爲Double一個類型別名),然後調用

public func moment(_ milliseconds: Int) -> Moment 
相關問題