I have a method what I want to call after -viewDidLoad
and in background thread. Is there way to combine this two methods:
[self performSelector:(SEL) withObject:(id) afterDelay:(NSTimeInterval)]
and
[self performSelectorInBackground:(SEL) withObject:(id)]
?
Grand Central Dispatch has dispatch_after()
which will execute a block after a specified time on a specified queue. If you create a background queue, you will have the functionality you desire.
dispatch_queue_t myBackgroundQ = dispatch_queue_create("com.romanHouse.backgroundDelay", NULL);
// Could also get a global queue; in this case, don't release it below.
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC);
dispatch_after(delay, myBackgroundQ, ^(void){
[self delayedMethodWithObject:someObject];
});
dispatch_release(myBackgroundQ);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With