From d89df51792f588222a2da6cc18d5cd5d28992221 Mon Sep 17 00:00:00 2001 From: Tataru Robert Date: Wed, 21 Aug 2024 14:22:27 +0300 Subject: [PATCH] Fix: In case that were no features found, it would not throw any error, and also it uses force cast --- Sources/CodeScanner/ScannerViewController.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sources/CodeScanner/ScannerViewController.swift b/Sources/CodeScanner/ScannerViewController.swift index 87930cb..19d89fa 100644 --- a/Sources/CodeScanner/ScannerViewController.swift +++ b/Sources/CodeScanner/ScannerViewController.swift @@ -512,17 +512,22 @@ extension CodeScannerView.ScannerViewController: UIImagePickerControllerDelegate let features = detector.features(in: ciImage) - for feature in features as! [CIQRCodeFeature] { - qrCodeLink = feature.messageString! - if qrCodeLink.isEmpty { - didFail(reason: .badOutput) - } else { + if features.isEmpty { + didFail(reason: .badOutput) + } else { + for feature in features.compactMap({ $0 as? CIQRCodeFeature }) { + guard let qrCodeLink = feature.messageString, !qrCodeLink.isEmpty else { + didFail(reason: .badOutput) + continue + } + let corners = [ feature.bottomLeft, feature.bottomRight, feature.topRight, feature.topLeft ] + let result = ScanResult(string: qrCodeLink, type: .qr, image: qrcodeImg, corners: corners) found(result) }