I have a function that searches for text in a scanned document. The first time the function is executed I get the following error:
020-06-27 14:43:19.584321+0100 Foo[58201:3904738] Resource initialization failed: could not open file /System/Library/LinguisticData/RequiredAssets_en.bundle/AssetData/en.lm/variants.dat
The function is:
func recognizeText(
withCompletionHandler completionHandler: @escaping ([String], [UIImage]) -> Void) {
print ("Log 1")
queue.async {
let uiImages = (0..<self.cameraScan.pageCount).compactMap({
self.cameraScan.imageOfPage(at: $0) })
let images = uiImages.compactMap{$0.cgImage}
print ("Log 2")
let imagesAndRequests = images.map({ (image: $0,
request: VNRecognizeTextRequest()) })
print ("Log 3")
let textPerPage = imagesAndRequests.map { image,
request -> String in
let handler = VNImageRequestHandler(cgImage: image, options: [:])
print ("Log 4")
do {
print ("Log 5")
try handler.perform([request])
guard let observations = request.results as?
[VNRecognizedTextObservation] else { return "" }
print ("Log 6")
return observations.compactMap({
$0.topCandidates(1).first?.string }).joined(separator: "\n")
} catch {
print(error)
print ("Log 7")
return ""
}
}
DispatchQueue.main.async {
print ("Log 8")
completionHandler(textPerPage, uiImages)
}
}
}
On first execution text is match correctly but the log shows:
DocumentCameraViewController() called Log 1 Log 2 Log 3 Log 4 Log 5 2020-06-27 14:43:19.584321+0100 Foo[58201:3904738] Resource initialization failed: could not open file /System/Library/LinguisticData/RequiredAssets_en.bundle/AssetData/en.lm/variants.dat 2020-06-27 14:43:19.595998+0100 Foo[58201:3904738] Resource initialization failed: could not open file /System/Library/LinguisticData/RequiredAssets_en.bundle/AssetData/en.lm/variants.dat 2020-06-27 14:43:19.600817+0100 Foo[58201:3904738] Resource initialization failed: could not open file /System/Library/LinguisticData/RequiredAssets_en.bundle/AssetData/en.lm/variants.dat 2020-06-27 14:43:19.605562+0100 Foo[58201:3904738] Resource initialization failed: could not open file /System/Library/LinguisticData/RequiredAssets_en.bundle/AssetData/en.lm/variants.dat Log 6
On subsequent executions no errors are logged.
I have no idea how to resolve the issue as no errors are directly reported to my function.