两种写法:
/*
调度组最重要的任务:监听一组任务的完成
*/
-(void)group1{
//创建调度组
dispatch_group_t group = dispatch_group_create();
//创建队列
dispatch_queue_t t = dispatch_get_global_queue(0, 0);
//调度组监听队列调度任务
dispatch_group_async(group, t, ^{
NSLog(@"download A %@",[NSThread currentThread]);
});
dispatch_group_async(group, t, ^{
NSLog(@"download b %@",[NSThread currentThread]);
});
dispatch_group_notify(group, t, ^{
NSLog(@"come here");
});
}
-(void)group2{
//1.创建调度组
dispatch_group_t group = dispatch_group_create();
//2.创建队列
dispatch_queue_t t = dispatch_get_global_queue(0, 0);
//3.调度组
//1>入组
dispatch_group_enter(group);
dispatch_group_async(group, t, ^{
NSLog(@"download A %@",[NSThread currentThread]);
//2>出组
dispatch_group_leave(group);
});
//1>入组
dispatch_group_enter(group);
dispatch_group_async(group, t, ^{
NSLog(@"download A %@",[NSThread currentThread]);
//2>出组
dispatch_group_leave(group);
});
dispatch_group_notify(group, t, ^{
NSLog(@"come here");
});
}
网友评论