From 1466f9c0bdab2f314b44a8cba1e1856eb5c8bbf8 Mon Sep 17 00:00:00 2001 From: chronikum <34622984+chronikum@users.noreply.github.com> Date: Thu, 28 Dec 2017 17:34:52 +0100 Subject: [PATCH] Update QRCode.swift Updated for Swift 4 and Xcode 9 --- QRCode/Source/QRCode.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/QRCode/Source/QRCode.swift b/QRCode/Source/QRCode.swift index d278d12..b328609 100644 --- a/QRCode/Source/QRCode.swift +++ b/QRCode/Source/QRCode.swift @@ -100,7 +100,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate { colorFilter.setValue(backColor, forKey: "inputColor1") let transform = CGAffineTransform(scaleX: 10, y: 10) - let transformedImage = qrFilter.outputImage!.applying(transform) + let transformedImage = qrFilter.outputImage!.transformed(by: transform) let image = UIImage(ciImage: transformedImage) @@ -179,7 +179,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate { return } - if !session.canAddInput(videoInput) { + if !session.canAddInput(videoInput!) { print("can not add input device") return } @@ -189,7 +189,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate { return } - session.addInput(videoInput) + session.addInput(videoInput!) session.addOutput(dataOutput) dataOutput.metadataObjectTypes = dataOutput.availableMetadataObjectTypes; @@ -210,7 +210,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate { if currentDetectedCount > maxDetectedCount { session.stopRunning() - completedCallBack!(codeObject.stringValue) + completedCallBack!(codeObject.stringValue!) if autoRemoveSubLayers { removeAllLayers() @@ -274,8 +274,8 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate { /// previewLayer lazy var previewLayer: AVCaptureVideoPreviewLayer = { let layer = AVCaptureVideoPreviewLayer(session: self.session) - layer?.videoGravity = AVLayerVideoGravityResizeAspectFill - return layer! + layer.videoGravity = AVLayerVideoGravity.resizeAspectFill + return layer }() /// drawLayer @@ -285,7 +285,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate { /// input lazy var videoInput: AVCaptureDeviceInput? = { - if let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) { + if let device = AVCaptureDevice.default(for: AVMediaType.video) { return try? AVCaptureDeviceInput(device: device) } return nil