小编Kin*_*ing的帖子

如何在swift 4中进行两个并发API调用

在此先感谢您的帮助,我有两个API调用,两个都是并发的,任何调用都可以先成功(我不想按顺序调用),两个调用成功后,我必须停止我的活动指示器并重新加载我的tableView ,这是我的代码,但我不知道这是否正确以及如何重新加载我的tableView并停止我的活动指示器.

func downloadDetails(){
    let operationQueue: OperationQueue = OperationQueue()
    let operation1 = BlockOperation() {
    WebServiceManager.getAData(format:A, withCompletion: {(data: Any? , error: Error?) -> Void in

          if let success = data {
              DispatchQueue.main.async {
                  (success code)
              }
           }
        })

        let operation2 = BlockOperation() {
        webServiceManager.getBData(format: B, withCompletion: {(data: Any? , error: Error?) -> Void in

                if let success = data {
                    DispatchQueue.main.async {
                       (success code)
                    }
                }
            })
        }
        operationQueue.addOperation(operation2)
    }
    operationQueue.addOperation(operation1)
}
downloadDetails() "calling function"
Run Code Online (Sandbox Code Playgroud)

nsoperation nsoperationqueue ios swift4 swift4.1

3
推荐指数
1
解决办法
3824
查看次数

标签 统计

ios ×1

nsoperation ×1

nsoperationqueue ×1

swift4 ×1

swift4.1 ×1