Wait for an async methods to finish in a for loop

前端 未结 4 831
庸人自扰
庸人自扰 2021-02-09 14:38

I have a for loop containing three asynchronous methods, and I want to make some treatment after this 3 async methods are finished.

 -(void)getAllUsersInformatio         


        
4条回答
  •  一向
    一向 (楼主)
    2021-02-09 15:19

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // Background work
           for(User *user in users){
              [self getUserInfo:user];
           }
    
        dispatch_async(dispatch_get_main_queue(), ^{
         //reload tableview , this is on main thread.
        });
    });
    

提交回复
热议问题