In my iPhone app I got several places where I can do a
[object performSelector: withObject: afterDelay:]
call. All lead to the same method. Now, in that method I want to execute some code only on the latest call of it. If it was the first, I could just do [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(thisMethod) object:nil]
and be sure it gets called once.
But, is there a way to tell if there are any other method calls waiting to be executed?
I could use a counter in this class that I would increment each time I set this perform after delay, then decrement it at start of each call and only execute the code if this counter is zeroed. But I'm wondering if it's the best/acceptable approach...