TimSim TimSim - 7 months ago 306
Swift Question

How to convert/cast NSNumber to Int64?

Just like the title says. I had to store

Int64
in
NSUserDefaults
and the only way I found to do that was storing it as
NSNumber
like

NSNumber(longLong: someInt64)


but I don't know how to convert it back to Int64.

Answer

Use the longLongValue property of NSNumber to retrieve the Int64 value:

let someInt64: Int64 = 314

let n = NSNumber(longLong: someInt64)

let m = n.longLongValue  // m is an `Int64`