1.GCD
//GCD
//創建子線程dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
//發送網路請求
self.sendData()
//主線程
dispatch_async(dispatch_get_main_queue(), { () -> Void in
//更新UI
self.updateLable()
})
})
2.NSOperationQueue
//NSOperationQueue
let myOperation = NSBlockOperation { () -> Void in
self.sendData()
}
NSOperationQueue().addOperation(myOperation)
//NSThread
NSThread.detachNewThreadSelector("sendData", toTarget: self, withObject: nil)