如何提取具有最高置信度值的标签并在 Swift 中打印出来?

How do I extract the label with the highest confidence value and print it out in Swift?

private func showResults(_ results: [(label: String, confidence: 
Float)]?) {
    var resultsText = Constants.failedToDetectObjectsMessage
    if let results = results {
      resultsText = results.reduce("") { (resultString, result) -> 
String in
        let (label, confidence) = result
        return resultString + "\(label): \(String(describing: 
confidence))\n"
      }
    }
    resultsAlertController.message = resultsText
    resultsAlertController.popoverPresentationController?.sourceRect = self.annotationOverlayView.frame
    resultsAlertController.popoverPresentationController?.sourceView = self.annotationOverlayView
    present(resultsAlertController, animated: true, completion: nil)
    print(resultsText)
}

这是我试过的示例代码。如何提取具有最高置信度值的标签并打印出来?

了解哪个标签具有最高置信度的方法是在 results 数组上调用 max(by:)。参见 https://developer.apple.com/documentation/swift/sequence/2906531-max

private func showResults(_ results: [(label: String, confidence: Float)]?) {
    if let results = results {
        let biggest = results.max { [=10=].confidence < .confidence }
        if let biggest = biggest {
            let (label, confidence) = biggest
            // ...
        }
    }
}