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


}
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息