class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() clorse { (json) in print(json) } } func clorse(completion:@escaping (_ json: [String])->()) { let workingQueue = DispatchQueue(label: "workingQueue") workingQueue.async { // 延迟操作 print("努力工作") Thread.sleep(forTimeInterval: 2.0) let json = ["ac","mym"] DispatchQueue.main.async { print("结束工作") // 主线程更新 回调 completion(json) } } } }
时间: 2024-10-19 17:21:04