- (void)start
{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
for (int i = 0; i < users.count; i ++) {
NSString *url = [NSString stringWithFormat:reposListUrl, users[i]];
// 请求每个用户的所有库
[XTNetwork requestWithURL:url parameter:nil methods:GET successResult:^(id result) {
NSArray *data = result;
NSMutableArray *names = [NSMutableArray array];
for (int i = 0; i < data.count; i ++) {
NSDictionary *dic = data[i];
NSString *name = dic[@"name"];
[names addObject:name];
}
NSLog(@"第一层的 i = %d", i);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_semaphore_t semaphore1 = dispatch_semaphore_create(0);
for (int j = 0; j < names.count; j ++) {
NSString *detailUrl = [NSString stringWithFormat:reposDetailUrl, users[i], names[j]];
[XTNetwork requestWithURL:detailUrl parameter:nil methods:GET successResult:^(id result) {
NSLog(@"第二层的 i = %d, j = %d", i, j);
dispatch_semaphore_signal(semaphore1);
}];
dispatch_semaphore_wait(semaphore1, DISPATCH_TIME_FOREVER);
}
dispatch_semaphore_signal(semaphore);
});
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
});
}
2023-01-13 20:38:26.257297+0800 XTWeibo[3158:204344] 第一层的 i = 0
2023-01-13 20:38:26.261531+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 0
2023-01-13 20:38:27.276864+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 1
2023-01-13 20:38:28.051853+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 2
2023-01-13 20:38:29.074902+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 3
2023-01-13 20:38:29.794057+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 4
2023-01-13 20:38:30.509545+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 5
2023-01-13 20:38:31.227020+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 6
2023-01-13 20:38:31.943710+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 7
2023-01-13 20:38:32.641432+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 8
2023-01-13 20:38:33.376847+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 9
2023-01-13 20:38:34.093713+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 10
2023-01-13 20:38:34.914586+0800 XTWeibo[3158:204344] 第二层的 i = 0, j = 11
2023-01-13 20:38:35.992519+0800 XTWeibo[3158:204344] 第一层的 i = 1
2023-01-13 20:38:37.264356+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 0
2023-01-13 20:38:37.985781+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 1
2023-01-13 20:38:39.314381+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 2
2023-01-13 20:38:40.133719+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 3
2023-01-13 20:38:41.057140+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 4
2023-01-13 20:38:42.182486+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 5
2023-01-13 20:38:43.219709+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 6
2023-01-13 20:38:44.025821+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 7
2023-01-13 20:38:44.844844+0800 XTWeibo[3158:204344] 第二层的 i = 1, j = 8
原文地址:https://blog.csdn.net/sinat_30162391/article/details/128679422
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_25434.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!