Without creating multiple NSTimer
instances, how would one achieve an NSTimer
to fire a specific or multiple method with different intervals in a sequence. For example method1 (0.3 sec), method2 (0.5), method3 (0.7) and so on.
I would appreciate if someone could please share any example code.
NSTimer
itself does not provide that functionality, it fires either once or repeatedly at fixed intervals. You will require multiple timers to achieve this effect, or move away fromNSTimer
entirely.create an timer with selector with timeinterval = 0.1 from there in the selector method, you can check by keeping a static float variable and add 0.1 to it everytime like:
then check the counter value and call ur methods..
I'm not sure what your final goal is with this but after reading your question I would recommend to try the following way, maybe this is what you'd look for.
you should put this code where you normally wanted to start the same
NSTimer
class with different intervals (what is not possible, unfortunately).and when need to unschedule all those selectors queued, use this code.
i beleive you should pass current time interval to the fired selector and further handle it there. if time interval is 0.3 you call method1, 0.5 - method2, there's most likely no other way to implement this
Make a wrapper to wrap the
NSTimer
method call like this:You can call this method and pass the interval and selector method as per your requirement.