How to get the current queue name in swift 3

前端 未结 6 924
遇见更好的自我
遇见更好的自我 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:31

    Now DispatchQueue has label property.

    The label you assigned to the dispatch queue at creation time.

    var label: String { get } 
    

    It seems been existed from first, maybe not been exposed via public API.

    macOS 10.10+
    

    And please use this only to obtain human-readable labels. Not to identify each GCDQ.

    If you want to check whether your code is running on certain GCDQ, you can use dispatchPrecondition(...) function.

提交回复
热议问题