Fast code in the playground versus the actual class

The odd thing is happening here. The following code:

String(Int(date.timeIntervalSince1970*1000))

works on the playground, but not in the classroom. It crashes with EXC_BAD_INSTRUCTION.

Any ideas why? Alternatively, how do I get a string from the above NSTimeInterval?

Thanks in advance!

Edit: I need the result as Int, therefore 1402324472549, not 1402324472549.64, for example.

+4
source share
3 answers

Inside the class definition:

var date = NSDate()
let myDateString = String(Int64(date.timeIntervalSince1970()*1000))
println("Seconds = \(myDateString)")
+4
source

Not sure about the root cause, but it has something to do with type conversion. It works:

var date = NSDate()
var asString = "\(Int(date.timeIntervalSince1970*1000))"
println(asString)
+2
source

- , 32- int swift , . :

"\(floor(date.timeIntervalSince1970)"
+2

Source: https://habr.com/ru/post/1543866/


All Articles