How to check current thread in Swift 3? How to check current thread in Swift 3? multithreading multithreading

How to check current thread in Swift 3?


Looks like it's simply Thread.isMainThread in Swift 3.


Thread.isMainThread will return a boolean indicating if you're currently on the main UI thread. But this will not give you the current thread. It will only tell you if you are on the main or not.

Thread.current will return the current thread you are on.


I've made an extension to print the thread and queue:

extension Thread {    class func printCurrent() {        print("\r⚡️: \(Thread.current)\r" + "🏭: \(OperationQueue.current?.underlyingQueue?.label ?? "None")\r")    }}

Thread.printCurrent()

The result would be:

⚡️: <NSThread: 0x604000074380>{number = 1, name = main}🏭: com.apple.main-thread