Skip to content

Commit bc35850

Browse files
authored
Improving changes on feature detection safety
1 parent e24bd5a commit bc35850

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

Sources/CodeScanner/ScannerViewController.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -509,29 +509,27 @@ extension CodeScannerView.ScannerViewController: UIImagePickerControllerDelegate
509509
return
510510
}
511511

512-
var qrCodeLink = ""
513-
514512
let features = detector.features(in: ciImage)
515513

516-
if features.isEmpty {
514+
guard !features.isEmpty else {
517515
didFail(reason: .badOutput)
518-
} else {
519-
for feature in features.compactMap({ $0 as? CIQRCodeFeature }) {
520-
guard let qrCodeLink = feature.messageString, !qrCodeLink.isEmpty else {
521-
didFail(reason: .badOutput)
522-
continue
523-
}
516+
return
517+
}
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+
}
524523

525-
let corners = [
526-
feature.bottomLeft,
527-
feature.bottomRight,
528-
feature.topRight,
529-
feature.topLeft
530-
]
524+
let corners = [
525+
feature.bottomLeft,
526+
feature.bottomRight,
527+
feature.topRight,
528+
feature.topLeft
529+
]
531530

532-
let result = ScanResult(string: qrCodeLink, type: .qr, image: qrcodeImg, corners: corners)
533-
found(result)
534-
}
531+
let result = ScanResult(string: qrCodeLink, type: .qr, image: qrcodeImg, corners: corners)
532+
found(result)
535533
}
536534
}
537535

0 commit comments

Comments
 (0)