NSInteger (which is a type alias for
Int in Swift) is a 32-bit
integer on 32-bit platforms like the iPhone 5.
The result of
NSInteger(NSDate().timeIntervalSince1970) * 1000
1480106653342 (at this moment) and does not fit into the
-2^31 ... 2^31-1 of 32-bit (signed) integers.
Therefore Swift aborts the execution. (Swift does not "truncate"
the result of integer arithmetic operations as it is done in some
other programming languages, unless you specifically use the
"overflow" operators like
You can use
Int64 for 64-bit computations on all platforms:
Int64(NSDate().timeIntervalSince1970 * 1000)
In your case, if a string is needed:
let lastLogin = String(Int64(NSDate().timeIntervalSince1970 * 1000))
Answer author Martin-r