I'm simply trying to initialise an NSDate object from epoch.
I have a dictionary object of type Dictionary<String, AnyObject> and I know that this key corresponds to an Int
But the Swift compiler is complaining that the NSDate line has an Extra argument 'timeIntervalSince1970' in call
if let respondedDate : Int = (responseDict["expiry_date"] as AnyObject) as? Int {
let expiryDate = NSDate(timeIntervalSince1970: respondedDate)
}
No idea what I am doing wrong here, this seems completely correct to me. Any ideas?
Thanks for the timely response. Here's the working code!
if let respondedDate : NSTimeInterval = (responseDict["expiry_date"] as AnyObject) as? NSTimeInterval {
let expiryDate = NSDate(timeIntervalSince1970: respondedDate)
}
Hopefully Xcode will be updated soon to make this error more descriptive rather than telling me that the there's an "extra argument"
It's expecting respondedDate to be a NSTimeInterval which is a Double. If you cast respondedDate to NSTimeInterval instead it should work.
Declare respondedDate as an NSTimeInterval instead of an Int. Swift is strongly typed, so it isn't able to automatically cast an Int to NSTimeInterval (which is a typealias for Double).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With