I have added the library MBDocCapture to my project using CocoaPods. Now, as its readme suggests, I made my view controller conform to ImageScannerControllerDelegate
and added all 4 protocol methods to my code:
extension DocumentUploaderViewController: ImageScannerControllerDelegate {
func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithResults results: ImageScannerResults) {
scanner.dismiss(animated: true)
}
func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithPage1Results page1Results: ImageScannerResults, andPage2Results page2Results: ImageScannerResults) {
scanner.dismiss(animated: true)
}
func imageScannerControllerDidCancel(_ scanner: ImageScannerController) {
scanner.dismiss(animated: true)
}
func imageScannerController(_ scanner: ImageScannerController, didFailWithError error: Error) {
scanner.dismiss(animated: true)
}
}
Now, Xcode (10.2.1) complains that I'm still missing some protocol stubs:
Type 'DocumentUploaderViewController' does not conform to protocol 'ImageScannerControllerDelegate'
Do you want to add protocol stubs?
When I press Fix
, Xcode adds the didFailWithError
method:
func imageScannerController(_ scanner: ImageScannerController, didFailWithError error: Error) {
}
...and then complains that I have added an invalid redeclaration of the method (because it was already there!):
Invalid redeclaration of 'imageScannerController(_:didFailWithError:)'
I have already tried:
None of these tries helped.
Any ideas?
You might have an Error
model (struct or class) defined in your project explicitly which is causing this issue.
To fix this, you have two options:
MyError
didFailWithError error: Swift.Error
This error always appears when there is a conflict in the scope of the model. Current delegate stubs written for extension DocumentUploaderViewController: ImageScannerControllerDelegate
are considering the Error
model of your project defined in local scope, while the delegate stub expects the Error
model defined in Swift.
Check if you have set the delegate to the appropriate view controller. Something like:
let scannerViewController = ImageScannerController()
scannerViewController.imageScannerDelegate = self
Dont add methods manually. Remove all methods & when the xcode complains - "Type 'DocumentUploaderViewController' does not conform to protocol 'ImageScannerControllerDelegate' Do you want to add protocol stubs?"
Simply click fix. And you are done .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.