ios - 如何在 swift 中使用 performSelectorInBackground?

标签 ios swift performselector

import UIKit


class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @objc class myClass:NSObject {

        func myFunc(){
            for var i = 0; i < 10000; i++ {
                print(i,[NSThread.currentThread()]);
            }
        }
    }
    var myObj = myClass()

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        _ = NSThread.init(target: myObj, selector:Selector(myObj.myFunc()), 

    object: nil)
        }
    }

当我运行上面的代码时,Xcode出现异常,信息是

[NSThread initWithTarget:selector:object:]: target does not implement selector

如何在 swift 中使用 performSelectorInBackground ??

最佳答案

简单的回答:你不需要。使用 dispatch_async。

关于ios - 如何在 swift 中使用 performSelectorInBackground?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34648201/

相关文章:

ios - 播放视频时未调用 UITableView didEndDisplaying

ios - 如何才能以这样的方式存储数据:删除然后安装ios后数据不会丢失?

xcode - swift 2 arc4random

ios - 从 performSelector 传递对象

objective-c - 在未知类型的类中调用静态方法

ios - 在 XCTestCase 中对类方法进行单元测试

objective-c - 如何在 Objective C 中声明一个以另一个变量的值命名的变量

ios - Xcode 5 - 应用程序通过验证,通过 iTunes 安装后图标变灰

ios - iOS中performSelector有什么用

ios - 自动布局应用于 UIButton 时如何移动 UIBarButton?