【问题标题】:How to execute a method in background in Swift [duplicate]如何在 Swift 中在后台执行方法 [重复]
【发布时间】:2014-11-09 22:00:59
【问题描述】:

我想在 Google 上弄清楚,但我找不到“如何在 Swift 的后台执行方法”。

有没有类似的东西

performsSelectorInBackground:

来自 Objective-C?

提前致谢!

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    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
    }
    

    【讨论】:

      【解决方案2】:

      NSOperation 和 Grand Central Dispatch (GCD) 在 Swift 中都可用。我将从阅读 Apple 的 GCD 和 NSOperationQueue 文档开始:

      https://developer.apple.com/LIBRARY/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/index.html

      https://developer.apple.com/library/ios/documentation/cocoa/reference/NSOperationQueue_class/index.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-10
        相关资源
        最近更新 更多