How can I pass a parameter to the method called by a NSTimer? My timer looks like this:
[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selec
Not a direct answer to the question but since i ran into this while searching and i needed something different it may help someone. I wanted to call a funciton in a helper class, that i needed to pass in the UIViewController
, rather than passing it with the userinfo which would not allow me to call the function manually elsewhere i created another function which the timer would call and called the function that i was interested in from there. A workaround that helped.
Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(self.timerFired), userInfo: nil, repeats:true);
func timerFired() {
myFunction(controller: self)
}