I am using dispatch_after()
and dispatch_get_current_queue()
to delay a method at the moment. For example, delay for 1 second:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[self someMethod];
});
As dispatch_get_current_queue()
is deprecated from iOS 6, is there any other equivalent way to do this without creating another separated method for performSelector:withObject:afterDelay:
?
A similar question here but still using the deprecated way. Thanks!
EDIT:
From Peter Segerblom's answer:
// Without updating UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Hello World");
});
// updating UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[imageView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:imageView];
});
Cheers!