HomeiOS Developmentswift - SwiftyTesseract IOS - Stack Overflow

swift – SwiftyTesseract IOS – Stack Overflow


It doesn’t matter what code i alter or add Swifty Tesseract won’t construct i’ve 4 errors that won’t go away it doesn’t matter what i do

import SwiftUI
import Basis
import Imaginative and prescient
import SwiftyTesseract

struct DocumentScanningView: View {
    @State non-public var picture: UIImage?
    @State non-public var isImagePickerPresented = false
    @State non-public var sourceType: UIImagePickerController.SourceType = .photoLibrary
    @EnvironmentObject var chatView: AITutorChatViewModel

    let tesseract = SwiftyTesseract(languages: [.english])

    var physique: some View {
        VStack {
            if let picture = picture {
                Picture(uiImage: picture)
                    .resizable()
                    .scaledToFit()
            } else {
                Textual content("No picture chosen")
            }

            HStack {
                Button("Choose Picture from Library") {
                    sourceType = .photoLibrary
                    isImagePickerPresented = true
                }

                if UIImagePickerController.isSourceTypeAvailable(.digital camera) {
                    Button("Seize Picture") {
                        sourceType = .digital camera
                        isImagePickerPresented = true
                    }
                }
            }
            .padding()
            .sheet(isPresented: $isImagePickerPresented) {
                OCRImagePicker(picture: $picture, sourceType: sourceType, completionHandler: { recognizedText in
                    chatView.sendOCRTextToAPI(textual content: recognizedText)
                }, tesseract: tesseract)
            }
        }
    }
}

struct OCRImagePicker: UIViewControllerRepresentable {
    @Binding var picture: UIImage?
    var sourceType: UIImagePickerController.SourceType
    var completionHandler: ((String) -> Void)?
    var tesseract: SwiftyTesseract

    func makeUIViewController(context: Context) -> UIImagePickerController {
        let imagePickerController = UIImagePickerController()
        imagePickerController.sourceType = sourceType
        imagePickerController.delegate = context.coordinator
        return imagePickerController
    }

    func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
        let dad or mum: OCRImagePicker

        init(_ dad or mum: OCRImagePicker) {
            self.dad or mum = dad or mum
        }

        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo information: [UIImagePickerController.InfoKey: Any]) {
            if let uiImage = information[.originalImage] as? UIImage {
                dad or mum.picture = uiImage
                dad or mum.tesseract.performOCR(on: uiImage) { (consequence) in
                    swap consequence {
                    case .success(let recognizedText):
                        DispatchQueue.primary.async {
                            dad or mum.completionHandler?(recognizedText)
                        }
                    case .failure(let error):
                        print("Error performing OCR with SwiftyTesseract: (error)")
                    }
                }
            }

            picker.dismiss(animated: true)
        }

        func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
            picker.dismiss(animated: true)
        }
    }
}

Can’t name worth of non-function kind ‘module’

Reference to member ‘english’ can’t be resolved and not using a contextual kind

Can’t discover kind ‘SwiftyTesseract’ in scope

Sort of expression is ambiguous with out extra context

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments