swift - "Ambiguous reference to member 'scheduledTimerWithTimeInterval( _:invocation:repeats:)'" -


i'm trying set timer run event periodically, described here. hashtag parameter has been deprecated, tried rewrite starttimer code accordingly:

func starttimer() {     let theinterval: nstimeinterval = 5.0      self.timer = nstimer.scheduledtimerwithtimeinterval     (         interval: theinterval,         target: self,         selector: selector("timertick:"),         userinfo: "hello!",         repeats: true     ) } 

problem is, keep getting error: "ambiguous reference member 'scheduledtimerwithtimeinterval( _:invocation:repeats:)'". i'm not trying run scheduledtimerwithtimeinterval( _:invocation:repeats:), i'm trying run scheduledtimerwithinterval:target:selector:userinfo:repeats. i'd think obvious parameters i'm passing.

what need differently?

there 2 problems:

  1. it confused newline , whitespace between scheduledtimerwithtimeinterval , open parentheses.

  2. you should not supply first parameter label.

so, do:

timer = nstimer.scheduledtimerwithtimeinterval(     2.0,     target: self,     selector: #selector(timertick(_:)),     userinfo: "hello!",     repeats: true ) 

note, replaced selector("timertick:") #selector syntax.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -