Skip to content

Commit d89df51

Browse files
committed
Fix: In case that were no features found, it would not throw any error, and also it uses force cast
1 parent 34da57f commit d89df51

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Sources/CodeScanner/ScannerViewController.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,22 @@ extension CodeScannerView.ScannerViewController: UIImagePickerControllerDelegate
512512

513513
let features = detector.features(in: ciImage)
514514

515-
for feature in features as! [CIQRCodeFeature] {
516-
qrCodeLink = feature.messageString!
517-
if qrCodeLink.isEmpty {
518-
didFail(reason: .badOutput)
519-
} else {
515+
if features.isEmpty {
516+
didFail(reason: .badOutput)
517+
} else {
518+
for feature in features.compactMap({ $0 as? CIQRCodeFeature }) {
519+
guard let qrCodeLink = feature.messageString, !qrCodeLink.isEmpty else {
520+
didFail(reason: .badOutput)
521+
continue
522+
}
523+
520524
let corners = [
521525
feature.bottomLeft,
522526
feature.bottomRight,
523527
feature.topRight,
524528
feature.topLeft
525529
]
530+
526531
let result = ScanResult(string: qrCodeLink, type: .qr, image: qrcodeImg, corners: corners)
527532
found(result)
528533
}

0 commit comments

Comments
 (0)