How to get the current queue name in swift 3

前端 未结 6 933
遇见更好的自我
遇见更好的自我 2020-12-23 21:52

We have function like this in swift 2.2 for printing a log message with the current running thread:

func MyLog(_ message: String) {
    if Thread.isMainThre         


        
6条回答
  •  孤城傲影
    2020-12-23 22:37

    If you don't like unsafe pointers and c-strings, there is another, safe solution:

    if let currentQueueLabel = OperationQueue.current?.underlyingQueue?.label {
        print(currentQueueLabel)
        // Do something...
    }
    

    I don't know any cases when the currentQueueLabel will be nil.

提交回复
热议问题