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:
it confused newline , whitespace between
scheduledtimerwithtimeinterval
, open parentheses.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
Post a Comment