Swift 2.x
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let image = self.loadImage()
// 回到主线程更新UI
dispatch_async(dispatch_get_main_queue()) {
self.imageView.image = image
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(1.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
print("test")
}
Swift 4.0
DispatchQueue.global(qos: .userInitiated).async {
let image = self.loadImage()
// back to the main thread
DispatchQueue.main.async {
self.imageView.image = image
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
print("Are we there yet?")
}
版权声明:本文为jacob_ios原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。