Wait until multiple networking requests have all executed - including their completion blocks

后端 未结 4 1127
攒了一身酷
攒了一身酷 2020-11-27 10:33

I have multiple operations (they\'re AFNetworking requests) with completion blocks that takes some time to execute, and a Core Data object that needs to be saved at the end

4条回答
  •  旧巷少年郎
    2020-11-27 10:51

    My requirements were those of do many request from an array of String (URL)

    func updateSourceData(element: Int) {
    
        if element > availableUrls.count - 1 {
            return
        }
    
        let service = SourceDataServiceDao()
        let currentUrl = availableUrls[element]
        service.fooCall(url: currentUrl, completion: { (response, error) -> Void in
            self.updateSourceData(element + 1)
        })
    
    }
    

    Obviously, in this way calls are made in cascade, not N asynchronous calls.

提交回复
热议问题