好的,所以我在Xcode 8中发现了新的Swifty Dispatch API 。我使用DispatchQueue.main.async获得了乐趣,并且我一直在Xcode的Dispatch模块中查找所有新的API。 但我也使用dispatch_once来确保像单身人士创build和一次性设置不会执行多次(即使在multithreading环境中)… dispatch_once无处可查找新的调度模块? static var token: dispatch_once_t = 0 func whatDoYouHear() { print("All of this has happened before, and all of it will happen again.") dispatch_once(&token) { print("Except this part.") } }
我在Swift 2.x(甚至1.x)项目中有很多代码,看起来像这样: // Move to a background thread to do some long running work dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let image = self.loadOrGenerateAnImage() // Bounce back to the main thread to update the UI dispatch_async(dispatch_get_main_queue()) { self.imageView.image = image } } 或者像这样的东西来延迟执行: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { print("test") } 或者Grand Central Dispatch API的各种其他用途… 现在,我已经在Swift 3的Xcode 8(beta)中打开了我的项目,我得到了各种各样的错误。 […]