获取Swift 3中的GCD标签

时间:2016-10-21 23:47:10

标签: ios xcode swift3 grand-central-dispatch xcode8

我有一些代码可以获取当前GCD队列的标签,以便在Swift 2中看起来像这样:

if let queueName
    = String(UTF8String: dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) where !queueName.isEmpty {
    detailedMessage += "[" + queueName + "] "
}

在Xcode 8将其转换为Swift 3之后,它看起来像这样:

if let queueName
    = String(validatingUTF8: DISPATCH_CURRENT_QUEUE_LABEL.label), !queueName.IsEmpty {
    detailedMessage += "[" + queueName + "] "
}

但是,当我构建时,Xcode会给我以下错误:

  

元组类型'()'的值没有成员'label'

我还没有找到任何方法来获取Swift 3中的当前队列标签。有人可以帮忙吗?

谢谢,
大卫

已更新 这是上下文的功能:

public func log(_ message: String,
                tag: String,
                level: Logger.LogLevel,
                userInfo: [String : String]?,
                functionName: StaticString,
                fileName: StaticString,
                lineNumber: Int) {

    var detailedMessage = ""

    let formattedDate = self._dateFormatter.string(from: Date())
    detailedMessage += "\(formattedDate) "

    detailedMessage += "[\(level.description)] "

    if Thread.isMainThread {
        detailedMessage += "[main] "
    } else {
        if let threadName = Thread.current.name , !threadName.isEmpty {
            detailedMessage += "[" + threadName + "] "
        } else if let queueName
            = String(validatingUTF8: DISPATCH_CURRENT_QUEUE_LABEL.label) , !queueName.isEmpty {
            detailedMessage += "[" + queueName + "] "
        } else {
            detailedMessage += "[" + String(format:"%p", Thread.current) + "] "
        }
    }

    let lastPathComponent = NSString(stringLiteral: fileName).lastPathComponent
    detailedMessage += "[" + lastPathComponent + ":" + String(lineNumber) + "] "

    detailedMessage += "\(functionName) "

    let fullMessage = self.messageWithTag(tag, message: message)
    detailedMessage += "> \(fullMessage)"

    NSLog("\(fullMessage)")
}

1 个答案:

答案 0 :(得分:0)

您可以使用该方法

<FormControl type="username" onChange = {(event) => this.setState({email: event.target.value })} placeholder="Email" />