操作我得到了更多來自蘋果(所有的iPhone 5,iOS版10.3.3)在下面的代碼行更崩潰的報告:崩潰簡單的日期()在斯威夫特
let date = NSDate()
var dateComponents = DateComponents()
dateComponents.hour = -6
let calculatedDate = NSCalendar.current.date(byAdding: dateComponents, to: date as Date)
let selectStatement = "SELECT nr from info where date > \(UInt((calculatedDate!.timeIntervalSince1970)) * 1000);"
的crash-報告指出最後一行是問題線。所以看起來,calculateDate沒有實例化。
在以前版本的崩潰,甚至在第一線發生(iPhone 5,iOS版10.3.2)
我自己不能在iPhone 6S再現這些崩潰。
有什麼建議可能在這些陳述中出錯?
當它們具有本機Swift等效項時,不要使用Foundation類型。使用「日期」和「日曆」。 –
第一:你似乎在混合NSStuff('NSDate'和'Date',這導致了可以避免的劇組)和Swift Types。這不建議用於Swift 3代碼。 – Larme
「我...不能在iPhone 6s上重現這些崩潰。」...在iPhone 5模擬器上執行它,並且很容易重現。請參閱下面的[David的回答](https://stackoverflow.com/a/45996612/1271826)。 – Rob