Depending on the complexity of what you are doing, this small snippet may be enough:
double delayInSeconds = 2.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
Otherwise, you can take a look at NSTimer to schedule some code to run. You can even repeat one or more times.
It can be used like this, for example:
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(myMethod) userInfo:nil repeats:NO];
For a great answer with much more information on how to use it, check out this post and, of course, check the documentation .
source share