#pragma mark - load data - (void)loadDataSuccess:(void (^)(void))success failure:(void (^)(NSString *errorMessage))failure { NSInteger totalCount = 3; __block NSInteger requestCount = 0; Dispatch_semaphore_t sem = dispatch_semaphore_create(0); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {1 / / / / request / / request/request is successful to join the following code after successful requestCount + 1 when compared with totalCount is equal Illustrate three request has been completed, the semaphore plus 1 attention!!!!!!!!!! If (++requestCount == totalCount) {dispatch_semaphore_signal(sem); If (++requestCount == totalCount) {dispatch_semaphore_signal(sem); If (++requestCount == totalCount) {dispatch_semaphore_signal(sem); If (sem > 0) {if (sem > 0) {if (sem > 0) {if (sem > 0) {if (sem > 0) { Dispatch_semaphore_wait (sem, DISPATCH_TIME_FOREVER); // dispatch_async(dispatch_get_main_queue()) ^{// All requests completed // callback success(); }); }); }Copy the code
private let semaphore = DispatchSemaphore.init(value: 1)
private let requestQueue = DispatchQueue.init(label: "request.quque")
requestQueue.async { [unowned self] in
    semaphore.wait()
    footerAddRequest()
    semaphore.signal()
}
Copy the code