Created
April 24, 2019 21:13
-
-
Save thexande/5afe278545bef38c78a27897b4a56061 to your computer and use it in GitHub Desktop.
Print current thread information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Thread { | |
class func printCurrent() { | |
print("\r⚡️: \(Thread.current)\r" + "🏭: \(current.threadName)\r") | |
} | |
var threadName: String { | |
if let currentOperationQueue = OperationQueue.current?.name { | |
return "OperationQueue: \(currentOperationQueue)" | |
} | |
else if let underlyingDispatchQueue = OperationQueue.current?.underlyingQueue?.label { | |
return "DispatchQueue: \(underlyingDispatchQueue)" | |
} | |
else { | |
let name = __dispatch_queue_get_label(nil) | |
return String(cString: name, encoding: .utf8) ?? Thread.current.description | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment