I've searched around and am flummoxed by this riddle.
In Swift, Xcode 6.2, these lines work:
let day_seconds = 86400
let one_day_from_now = NSDate(timeIntervalSinceNow:86400)
But the following returns an error:
let day_seconds = 86400
let one_day_from_now = NSDate(timeIntervalSinceNow:day_seconds)
Console output:
"Playground execution failed: /var/folders/4n/88gryr0j2pn318sw_g_mgkgh0000gn/T/lldb/10688/playground625.swift:24:30: error: extra argument 'timeIntervalSinceNow' in call let one_day_from_now = NSDate(timeIntervalSinceNow:day_seconds)"
What's going on here? Why the NSDate trickiness?
It's because timeIntervalSinceNow
expect NSTimeInterval
which is Double
.
If you do:
let day_seconds = 86400
day_second is Int type which is not what the method expect. However when you type the number itself:
let one_day_from_now = NSDate(timeIntervalSinceNow:86400)
compiler implicit that you are passing Double, because it's what the method expect, which is ok.
The solution cancould be using
NSTimeInterval(day_seconds)
or Double(day_seconds)
which is the same or when you declare constant make sure it's double, for example:
let day_seconds = 86400.0
or
let day_seconds: Double = 86400
or
let day_seconds: NSTimeInterval = 86400
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