【发布时间】:2014-11-09 22:00:59
【问题描述】:
我想在 Google 上弄清楚,但我找不到“如何在 Swift 的后台执行方法”。
有没有类似的东西
performsSelectorInBackground:
来自 Objective-C?
提前致谢!
【问题讨论】:
我想在 Google 上弄清楚,但我找不到“如何在 Swift 的后台执行方法”。
有没有类似的东西
performsSelectorInBackground:
来自 Objective-C?
提前致谢!
【问题讨论】:
Because Swift is statically typed,实际上没有可以调用的选择器。
What you should be doing instead is Grand Central Dispatch (GCD):
dispatch_async(dispatch_get_main_queue()) {
// do your stuff here
}
【讨论】:
NSOperation 和 Grand Central Dispatch (GCD) 在 Swift 中都可用。我将从阅读 Apple 的 GCD 和 NSOperationQueue 文档开始:
【讨论】: