i modified the code so that you don't need block removal and adding etc.
In .h file of your viewController add
@property NSInteger currentCount;
And for your understanding and demonstration, lets assume we retry it when a touch happens on viewControllers view.
In .m file
- (void)viewDidLoad
{
[super viewDidLoad];
_currentCount=0;
[self doStuff:_currentCount];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//player dead, now start it again
_currentCount++;
[self doStuff:_currentCount];
}
- (void)doStuff:(NSInteger)count
{
NSLog(@"came top %d",count);
double delayInSeconds = 2;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if(count==self.currentCount){
//
// Do stuff
//
if([self shouldDoMoreStuff]) {
[self doStuff:count];
}
}
});
}
-(BOOL)shouldDoMoreStuff{
return YES;
}