Wait for an async methods to finish in a for loop

前端 未结 4 835
庸人自扰
庸人自扰 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:16

    Rop Answer with swift:

    func processData()
    {
        let group: dispatch_group_t  = dispatch_group_create()
    
        for item in data as! Object {
            dispatch_group_enter(group)
            item.process(completion: {() -> (Void) in
              dispatch_group_leave(group)
            })
          }
    
        dispatch_group_notify(group, dispatch_get_main_queue(), {
            //Do whatever you want
          })
    }
    

提交回复
热议问题