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.

4
  • Add here also the crash log. Commented Mar 20, 2018 at 7: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. Commented Mar 20, 2018 at 7:37
  • The stack backtrace shows that the crash happens on a 32-bit device, so the linked-to Q&A should solve your problem. Commented Mar 20, 2018 at 7:57
  • Thanks @MartinR, Currently we are supporting 32bit devices, got the answer from you post. Commented Mar 20, 2018 at 8:03

3 Answers 3

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)
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of casting you can simply use like this

let timeStamp = "\(Int(Date().timeIntervalSince1970*1000))"

1 Comment

That won't prevent the crash on 32-bit devices.
0

Just create String directly like this :

let time_stamp = "\(Date().timeIntervalSince1970*1000)"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.