twostraws / CodeScanner

A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
MIT License
1.02k stars 293 forks source link

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value #6

Closed neilbrazil closed 4 years ago

neilbrazil commented 4 years ago

Hi @twostraws

While using the package for the Hot Prospects tutorial, I get the following error when running on a device (iPhone 11 - iOS 13.4.1) after tapping the Scan QR button.

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

The Debug navigator highlights the following code from line 173 in the package.

override public func viewWillLayoutSubviews() { previewLayer.frame = view.layer.bounds }

Any help appreciated as loving the tutorials. Thank you

pd95 commented 4 years ago

I encountered the same problem here! As the viewWillLayoutSubviews() is called before viewDidAppear(), the access to the implicitly unwrapped previewLayer will crash.

pd95 commented 4 years ago

I've fixed the issue in a fork, tested it on my device successfully. See the open pull request.

twostraws commented 4 years ago

I believe this is resolved in #7.