首页 > 代码库 > Swift3.0-DisPatch

Swift3.0-DisPatch

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)
            }
            
            
        }
   
        
    }


}

 

Swift3.0-DisPatch