-1
let time = UInt64(NSDate().timeIntervalSince1970 * 1000.0)

I need to turn time into an AnyObject so I can use it for one library. How can I do so?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • 1
    Wrap an NSNumber around it? – matt Jun 09 '16 at 04:30
  • See for example http://stackoverflow.com/a/27305906/1187415 – Martin R Jun 09 '16 at 04:36
  • @matt This is however not the correct solution. Just wrapping an NSNumber around it is actually very non-swifty. Sad that this was marked as a duplicate as it is NOT. The correct solution here would be to replace AnyObject with Any, which is never mentioned in any of these posts. – Antwan van Houdt Jul 07 '16 at 09:55

1 Answers1

2

You need to box it inside an NSNumber, just the same as in Objective C.

let time = UInt64(NSDate().timeIntervalSince1970 * 1000.0)
let obj: AnyObject = NSNumber(unsignedLongLong: time)
Ewan Mellor
  • 6,747
  • 1
  • 24
  • 39
  • I think a better solution would be to replace AnyObject with Any instead, so you can use native swift arrays and collections. Converting to NSNumber is not very swifty. – Antwan van Houdt Jul 07 '16 at 09:57