0

I have a Dictionary object containing a large number (epoch time). When I try to cast it as an Int the result is an entirely different number. Trying to explicitly cast it as an Int64 or String both yield nil.

(lldb) po postData["createdDate"]
▿ Optional<AnyObject>
  ▿ Some : 1 elements
    - [0] : 1461681488000

(lldb) po postData["createdDate"] as? [Int]
▿ Optional<Array<Int>>
  ▿ Some : 1 elements
    - [0] : 1392607360

(lldb) po postData["createdDate"] as? [Int64]
nil

(lldb) po postData["createdDate"] as? [String]
nil

I'm on a 64 bit system and am well below the ceiling for an Int64. What's going on here, and how do I access this number?

PS: I'm aware dates should be transmitted in ISO 8601 format but this is the input I'm dealing with.

Fook
  • 5,320
  • 7
  • 35
  • 57

1 Answers1

2

Numeric dictionary objects are bridged to NSNumber.

Cast the value to NSNumber and get the longLongValue

if let epochTime = postData["createdDate"] as? NSNumber {
  let longNumber : Int64 = epochTime.longLongValue
}
vadian
  • 274,689
  • 30
  • 353
  • 361