animation - WatchKit "unrecognized selector sent to instance" when trying to fire an NSTimer object in Swift -
in watchkit extensions interfacecontroller.swift file call function, within awakewithcontext function, runs animated sequence of images.
i have used nstimer object time delay , fire off second animated sequence.
var nstimerobject:nstimer = nstimer.scheduledtimerwithtimeinterval(showcodedelay, target: self, selector: "showcode(countercode1)", userinfo: nil, repeats: false);
after first animation runs error preventing second animation being fired function specified in selector:
[code_break_watchkit_extension.interfacecontroller showcode(countercode1)]: unrecognized selector sent instance 0x60800014c3f0
i have ios device app , watchkit extension ticked in target membership
i found this thread on stackoverflow sent me down route.
another thread seemed suggest may need around "sharing" unclear.
it feels should simple i'm stumped.
i new please gentle on me :)
sorted it!
the problem in syntax setting selector function , passing parameters required function work.
i changed:
var nstimerobject:nstimer = nstimer.scheduledtimerwithtimeinterval(showcodedelay, target: self, selector: "showcode(countercode1)", userinfo: nil, repeats: false);
to:
var nstimerobject:nstimer = nstimer.scheduledtimerwithtimeinterval(showcodedelay, target: self, selector: "showcode:", userinfo: countercode1, repeats: false);
then had alter showcodedelay function declaration from:
func showcodedelay(countercode: int){ //code........ }
to:
func showcodedelay(nstimerobject:nstimer){ var tempcountercode = nstimerobject.userinfo as! nsnumber var countercode = int(tempcountercode) //code........ }
i'm getting head around wrongly first thought pointing selector @ function had created required parameters.
however looks when taking approach function being referred in selector has receive actual nstimer object , extract parameters required userinfo
once i'd figured out next problem had extracted value had passed in userinfo because xcode wanted me treat anyobject! can't expressed int extracted userinfo nstimerobject object nsnumber , downcast int
there may simpler more elegant way achieve downcast @ least worked.
Comments
Post a Comment