Timestamp function that has been working reliably just caused EXC_BAD_INSTRUCTION

梦想与她 提交于 2019-11-27 16:23:08

Your code will crash on all 32-bit platforms (such as iPhone 4, 5) because the result of

NSDate().timeIntervalSince1970 * 1000
// E.g.: 1464850525047.38

does not fit into a 32-bit integer. As a solution, use 64-bit integers:

Int64(NSDate().timeIntervalSince1970 * 1000)

Alternatively, if the intention is to create a string representing the milliseconds, use string formatting instead of an integer conversion:

String(format:"%.0f", NSDate().timeIntervalSince1970 * 1000)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!