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


}

 

posted @ 2016-12-22 09:36  三更小新  阅读(178)  评论(0编辑  收藏  举报