Код: Выделить всё
import UIKit
@preconcurrency import Vision
var queue = DispatchQueue.global()
extension UIImage {
@MainActor func detectBarcodes(completion: @Sendable @escaping ([VNBarcodeObservation]) ->()) {
let request = VNDetectBarcodesRequest()
request.queueFor(image: self) { result in
completion(result as? [VNBarcodeObservation] ?? [])
}
}
}
extension VNDetectBarcodesRequest {
@MainActor func queueFor(image: UIImage, completion: @Sendable @escaping ([Any]?) -> ()) {
let handler = VNImageRequestHandler(cgImage: image.cgImage!, orientation: .up, options: [:])
queue.async {
do {
let w = "ok here 1✅"
try handler.perform([self])
let b = "ok here 2✅"
} catch {
let c = "error here❌" //
Подробнее здесь: [url]https://stackoverflow.com/questions/79445249/vndetectbarcodesrequest-throws-an-error-in-swift-playground[/url]