0

When creating a time timestamp from Date() function app is getting crash rarely, Is it the right way to handle it?

let time_stamp = String(Int(Date().timeIntervalSince1970*1000))

The above code is getting crash rarely, in the test flight build. enter image description here

Added the log, line number 3216 is the above one.

Community
  • 1
  • 1
Joe
  • 859
  • 2
  • 10
  • 27
  • Add here also the crash log. – Alex Terente Mar 20 '18 at 07:33
  • Do you support 32-bit devices? Then this would be your problem: [Timestamp function that has been working reliably just caused EXC_BAD_INSTRUCTION](https://stackoverflow.com/questions/37584501/timestamp-function-that-has-been-working-reliably-just-caused-exc-bad-instructio). – Martin R Mar 20 '18 at 07:37
  • The stack backtrace shows that the crash happens on a 32-bit device, so the linked-to Q&A should solve your problem. – Martin R Mar 20 '18 at 07:57
  • Thanks @MartinR, Currently we are supporting 32bit devices, got the answer from you post. – Joe Mar 20 '18 at 08:03

3 Answers3

0

Don't cast to int, go to string directly and avoid the 32bit device length error

let time_stamp = String(format:"%.0f", NSDate().timeIntervalSince1970 * 1000)
fenix
  • 53
  • 6
0

Instead of casting you can simply use like this

let timeStamp = "\(Int(Date().timeIntervalSince1970*1000))"
Neha
  • 666
  • 1
  • 10
  • 17
0

Just create String directly like this :

let time_stamp = "\(Date().timeIntervalSince1970*1000)"
msp
  • 3,272
  • 7
  • 37
  • 49
Wendra
  • 507
  • 6
  • 8