Thread (NSThread in Objective-C) is a fairly thin wrapper around POSIX threads. It has some extra plumbing to interact with Apple's Foundation framework (which is common between iOS and Mac OS.)
The idea of targets and selectors is part of the Objective-C runtime, which is the basis of AppKit on Mac OS and UIKit for iOS. A selector is a method signature for the Objective-C dynamic method dispatch system. A target is an object that will receive a method call using a given selector.
Note that the Thread
class also has an initializer that takes a closure rather than a target/action. If you're determined to use Thread
s you could use that initializer instead (It will call your closure when it's started.)
That initializer is convenience init(block: @escaping () -> Void)
As others have said, you are better off using Grand Central Dispatch (GCD) for a couple of reasons.
It is not tied to the Objective-C runtime.
Creating and destroying threads is pretty expensive, needs a kernel
call, and ties up physical memory for the lifetime of the thread.
CGD lets the system maintain a pool of threads on your behalf. You either use an existing dispatch queue or create one of your own, and the system decides which threads to assign to that queue from a pool of threads.
It is also much cleaner to use from Swift than the Thread (NSThread) class.
Note that you could also ignore the Thread class and create POSIX threads directly, although I wouldn't really recommend that.