Swift wait for closure thread to finish

前端 未结 2 1327
别跟我提以往
别跟我提以往 2021-02-08 13:56

I\'m using a very simple swift project created with SPM where it includes Alamofire.

main.swift:

import Alamofire

Alamofire.request(\"https://google.com         


        
2条回答
  •  佛祖请我去吃肉
    2021-02-08 14:29

    For Swift 3

    let group = DispatchGroup()
    group.enter()
    DispatchQueue.global(qos: .userInitiated).async {
        // Do work asyncly and call group.leave() after you are done
        group.leave()
    }
    group.notify(queue: .main, execute: {
        // This will be called when block ends             
    })
    

    This code will be helpful when you need to execute some code after some task is done.

    Please add details about your question, then I can help you more.

提交回复
热议问题