dispatch_group_enter
dispatch_group_leave
dispatch_group_notify
里面 dispatch_group_notify
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
NSURLSessionDataTask *task = [session dataTaskWithURL:[NSURL URLWithString:@"https://www.baidu.com"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"请求 1 的值");
dispatch_group_leave(group);
}];
[task resume];
dispatch_group_enter(group);
NSURLSessionDataTask *task2 = [session dataTaskWithURL:[NSURL URLWithString:@"https://www.baidu.com"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"请求 2 的值");
dispatch_group_leave(group);
}];
[task2 resume];
dispatch_group_notify(group, dispatch_get_main_queue(), ^(){
NSLog(@"等待执行");
});
image.png