小编Shi*_*ira的帖子

如何使一个代码仅在另一个代码在 Swift 中完成后运行

我是异步和同步机制的新手。在我的代码中,我必须在另一行完成后才执行另一行代码。它看起来像这样:

    func something(){

    let workerQueue = DispatchQueue.global(qos: .userInitiated)
            workerQueue.async{
         let info = getInfoFromTheWeb()//I need the info value in order to perform the next line
         saveToDB(info: info)

      DispatchQueue.main.async {
       //update a label text in the ui after getting and saving that info
      }

    }
}
Run Code Online (Sandbox Code Playgroud)

请你的专业意见..

concurrency synchronization ios swift

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

标签 统计

concurrency ×1

ios ×1

swift ×1

synchronization ×1