I am building a kind of simulation with ever-smaller intervals between "ticks":
- (void) simulationTick {
if (self.currentTick >= kNumberOfSimulationTicks)
return; // recursion anchor
// ... do stuff ...
self.currentTick = self.currentTick + 1;
[self performSelector:@selector(simulationTick) withObject:nil
afterDelay:2.5 * pow(0.95,(double)self.currentTick)]; // acceleration
}
When leaving the Simulation screen, I want to stop the simulation, so I do this with
[NSObject cancelPreviousPerformRequestsWithTarget:self]
I first tried using
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self]
… but this didn’t work.
Why not?
Apparently there are many others who had the same problem and the same solution. But nowhere could I find exactly why. What’s the difference between the two?