Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Sources/QRCodeReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat

super.init()

sessionQueue.async {
sessionQueue.async { [weak self] in
guard let self = self else { return }
self.configureDefaultComponents(withCaptureDevicePosition: captureDevicePosition)
}
}
Expand Down Expand Up @@ -199,7 +200,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
*Notes: if `stopScanningWhenCodeIsFound` is sets to true (default behaviour), each time the scanner found a code it calls the `stopScanning` method.*
*/
public func startScanning() {
sessionQueue.async {
sessionQueue.async { [weak self] in
guard let self = self else { return }
guard !self.session.isRunning else { return }
Comment on lines +204 to 205
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer one line guard. Is it possible to inline the first statement?

guard let self = self, !self.session.isRunning else { return }


self.session.startRunning()
Expand All @@ -212,7 +214,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat

/// Stops scanning the codes.
public func stopScanning() {
sessionQueue.async {
sessionQueue.async { [weak self] in
guard let self = self else { return }
guard self.session.isRunning else { return }
Comment on lines +218 to 219
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here.

guard let self = self, self.session.isRunning else { return }


self.session.stopRunning()
Expand Down
8 changes: 4 additions & 4 deletions Sources/QRCodeReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ public class QRCodeReaderViewController: UIViewController {

view.backgroundColor = .black

codeReader.didFindCode = { [weak self] resultAsObject in
codeReader.didFindCode = { [weak self, weak builder] resultAsObject in
if let weakSelf = self {
if let qrv = builder.readerView.displayable as? QRCodeReaderView {
if let qrv = builder?.readerView.displayable as? QRCodeReaderView {
qrv.addGreenBorder()
}
weakSelf.completionBlock?(resultAsObject)
weakSelf.delegate?.reader(weakSelf, didScanResult: resultAsObject)
}
}

codeReader.didFailDecoding = {
if let qrv = builder.readerView.displayable as? QRCodeReaderView {
codeReader.didFailDecoding = { [weak builder] in
if let qrv = builder?.readerView.displayable as? QRCodeReaderView {
qrv.addRedBorder()
}
}
Expand Down