PartiallyFrozenOJ PartiallyFrozenOJ - 1 month ago 24
Swift Question

Swift 3.0 Thread Class Target Does not Implement Selector

I declare a property for my thread like so:

let loggingThread = Thread.init(target: self, selector: Selector(("loggingThreadProcess:")), object: nil)

@objc func loggingThreadProcess(object: AnyObject?) {

}


But I am getting the this error:

[NSThread initWithTarget:selector:object:]: target does not implement selector (*** -[_SwiftValue loggingThreadProcess:])

Any suggestions?

Answer

You should define it as:

let loggingThread = Thread.init(target: self, selector: #selector(loggingThreadProcess:), object: nil)