First, a newbie question: what's the difference between a selector and a method?
Secondly, a question with a beginner (who would have thought): I need to encode some code based on instance variables and pause between loops until some condition is met (of course, based on instance variables). I looked at a dream, I looked at NSThread. In both discussions working through these options, many asked why I am not using NSTimer, so I am here.
Good, so just getting a method (selector?) To run on a schedule is enough. The problem is that I donβt know how to see the instance variables that I set outside the timer from the NSTimer code. I need to see these variables from the NSTimer selection code, as I 1) will update their values, and 2) will set labels based on these values.
Here is some code that shows the concept ... In the end, I would also invalidate myVariable timers, however I excluded this for the sake of clarity.
MyClass *aMyClassInstance = [MyClass new]; [aMyClassInstance setMyVariable:0]; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doStuff) userInfo:nil repeats:YES]; [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(doSomeOtherStuff) userInfo:nil repeats:YES]; - (void) doStuff { [aMyClassInstance setMyVariable:11];
source share