Skip to content

Instantly share code, notes, and snippets.

@thexande
Created April 24, 2019 21:13
Show Gist options
  • Save thexande/5afe278545bef38c78a27897b4a56061 to your computer and use it in GitHub Desktop.
Save thexande/5afe278545bef38c78a27897b4a56061 to your computer and use it in GitHub Desktop.
Print current thread information
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