在swift中创建线程? [英] Creating threads in swift?
本文介绍了在swift中创建线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在swift中生成一个线程。
所以我有这一行:
I am trying to spawn a thread in swift. So I have this line:
。
。
。
. . .
let thread = NSThread(target: self, selector: doSomething(), object: nil)
。
。
。
. . .
doSomething是该类范围内的函数。
doSomething is a function within the scope of the class.
该行给出了这个错误:
找不到接受提供的参数的init()的重载
That line gives this error: "could not find an overload for init() that accepts the supplied arguments"
我在这里缺少什么?我可以在swift中创建一个新线程吗?
What am I missing here? Ho can I create a new thread in swift?
推荐答案
从Xcode 7.3和Swift 2.2开始,你可以使用特殊形式 #selector(...)
其中Objective-C将使用 @selector(...)
:
As of Xcode 7.3 and Swift 2.2, you can use the special form #selector(...)
where Objective-C would use @selector(...)
:
let thread = NSThread(target:self, selector:#selector(doSomething), object:nil)
这篇关于在swift中创建线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文