dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"2222");
});
3)保证方法在整个程序只执行一次
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
});
?
4)组操作,多个请求,请求完成后再执行操作
//创建一个组,
dispatch_group_t group = dispatch_group_create();
//开启一个任务下载图片1
__block UIImage *image1 = nil;
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//image1 = [];
});
__block UIImage *image2 = nil;
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//image2 = [];
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
//image1
//image2
});