Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Swift 3 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed May 10, 2017
1 parent 3ee9c8e commit b08dd38
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions QRIO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@
TargetAttributes = {
838FB5641D26A45E0065A950 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0830;
};
838FB56E1D26A45E0065A950 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0830;
};
};
};
Expand Down Expand Up @@ -329,7 +329,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -348,7 +348,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.QRIO;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -359,7 +359,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.QRIOTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -370,7 +370,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.QRIOTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
38 changes: 19 additions & 19 deletions QRIO/QRIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import UIKit
import AVFoundation
import CoreImage

public class QRInput: NSObject, AVCaptureMetadataOutputObjectsDelegate {
private var session: AVCaptureSession?
private var previewLayer: AVCaptureVideoPreviewLayer?
open class QRInput: NSObject, AVCaptureMetadataOutputObjectsDelegate {
fileprivate var session: AVCaptureSession?
fileprivate var previewLayer: AVCaptureVideoPreviewLayer?

public var imageScanCompletionBlock: ((string: String) -> ())?
open var imageScanCompletionBlock: ((_ string: String) -> ())?


public func scanForQRImage(previewIn previewContainer: UIView? = nil, rectOfInterest: CGRect? = nil, completion: ((string: String) -> ())) {
open func scanForQRImage(previewIn previewContainer: UIView? = nil, rectOfInterest: CGRect? = nil, completion: @escaping ((_ string: String) -> ())) {
session = AVCaptureSession()
let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)

do {
let input = try AVCaptureDeviceInput(device: device)
Expand All @@ -30,7 +30,7 @@ public class QRInput: NSObject, AVCaptureMetadataOutputObjectsDelegate {
}

let output = AVCaptureMetadataOutput()
output.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
session?.addOutput(output)
output.metadataObjectTypes = [AVMetadataObjectTypeQRCode]

Expand All @@ -43,28 +43,28 @@ public class QRInput: NSObject, AVCaptureMetadataOutputObjectsDelegate {
previewLayer!.videoGravity = AVLayerVideoGravityResizeAspectFill

}
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) { [weak self] in
DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async { [weak self] in
self?.session?.startRunning()
}

if let rectOfInterest = rectOfInterest, previewLayer = previewLayer {
output.rectOfInterest = previewLayer.metadataOutputRectOfInterestForRect(rectOfInterest)
if let rectOfInterest = rectOfInterest, let previewLayer = previewLayer {
output.rectOfInterest = previewLayer.metadataOutputRectOfInterest(for: rectOfInterest)
}
}

public func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
open func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
var QRCode: String?
for metadata in metadataObjects as! [AVMetadataObject] {
if metadata.type == AVMetadataObjectTypeQRCode {
QRCode = (metadata as! AVMetadataMachineReadableCodeObject).stringValue
}
}
if let code = QRCode {
imageScanCompletionBlock?(string: code)
imageScanCompletionBlock?(code)
}
}

public func finish() {
open func finish() {
imageScanCompletionBlock = nil
if let session = session {
session.stopRunning()
Expand All @@ -82,9 +82,9 @@ public class QRInput: NSObject, AVCaptureMetadataOutputObjectsDelegate {


public extension UIImage {
public static func QRImageFromString(string: String, containingViewSize: CGSize? = nil, correctionLevel: String = "L") -> UIImage? {
let stringData = string.dataUsingEncoding(NSISOLatin1StringEncoding)
let filter = CIFilter(name: "CIQRCodeGenerator")
public static func QRImageFrom(string: String, containingViewSize: CGSize? = nil, correctionLevel: String = "L") -> UIImage? {
let stringData = string.data(using: String.Encoding.isoLatin1)
let filter = CIFilter(name: "CICode128BarcodeGenerator")
filter?.setValue(stringData, forKey: "inputMessage")
filter?.setValue(correctionLevel, forKey: "inputCorrectionLevel")

Expand All @@ -97,10 +97,10 @@ public extension UIImage {
scaleY = size.height / resultImage.extent.size.height
}

let qrImage = resultImage.imageByApplyingTransform(CGAffineTransformMakeScale(scaleX, scaleY))
let qrImage = resultImage.applying(CGAffineTransform(scaleX: scaleX, y: scaleY))
let context = CIContext()
if let tempImage: CGImageRef = context.createCGImage(qrImage, fromRect: qrImage.extent) {
return UIImage(CGImage: tempImage)
if let tempImage: CGImage = context.createCGImage(qrImage, from: qrImage.extent) {
return UIImage(cgImage: tempImage)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion QRIOTests/QRIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QRIOTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
self.measure {
// Put the code you want to measure the time of here.
}
}
Expand Down

0 comments on commit b08dd38

Please sign in to comment.