Trouble Using Swift NSDate "timeIntervalSinceNow" -


i've searched around , flummoxed riddle.

in swift, xcode 6.2, these lines work:

let day_seconds = 86400 let one_day_from_now = nsdate(timeintervalsincenow:86400) 

but following returns 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: argument 'timeintervalsincenow' in call let one_day_from_now = nsdate(timeintervalsincenow:day_seconds)"

what's going on here? why nsdate trickiness?

it's because timeintervalsincenow expect nstimeinterval double.

if do:

let day_seconds = 86400 

day_second int type not method expect. when type number itself:

let one_day_from_now = nsdate(timeintervalsincenow:86400) 

compiler implicit passing double, because it's method expect, ok.

the solution cancould using nstimeinterval(day_seconds) or double(day_seconds) same or when declare constant make sure it's double, example:

let day_seconds = 86400.0 

or

let day_seconds: double = 86400 

or

let day_seconds: nstimeinterval = 86400 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -