gpt4 book ai didi

ios - 如何在 swift 中使用 performSelectorInBackground?

转载 作者:搜寻专家 更新时间:2023-10-31 22:47:27 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com