Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift4.1 migration #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions QRCode.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
45 changes: 30 additions & 15 deletions QRCode/QRCode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = joyios;
TargetAttributes = {
C2CBCCF11B050AD200E11353 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0940;
};
C2CBCCFC1B050AD200E11353 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0940;
};
};
};
Expand Down Expand Up @@ -254,13 +254,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -303,13 +313,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -329,6 +349,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -340,6 +361,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -352,14 +374,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
C2CBCD0A1B050AD200E11353 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -371,17 +394,13 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.joyios.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
C2CBCD0C1B050AD200E11353 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -390,22 +409,18 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.joyios.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
C2CBCD0D1B050AD200E11353 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = QRCodeTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.joyios.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
33 changes: 20 additions & 13 deletions QRCode/Source/QRCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
qrFilter.setDefaults()
qrFilter.setValue(stringValue.data(using: String.Encoding.utf8, allowLossyConversion: false), forKey: "inputMessage")

let ciImage = qrFilter.outputImage
guard let ciImage = qrFilter.outputImage else { return nil }

// scale qrcode image
let colorFilter = CIFilter(name: "CIFalseColor")!
Expand All @@ -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 = ciImage.transformed(by: transform)

let image = UIImage(ciImage: transformedImage)

Expand Down Expand Up @@ -179,6 +179,11 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
return
}

guard let videoInput = videoInput else {
print("unable to retrieve device input")
return
}

if !session.canAddInput(videoInput) {
print("can not add input device")
return
Expand All @@ -196,7 +201,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
dataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
}

open func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
open func metadataOutput(_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {

clearDrawLayer()

Expand All @@ -210,7 +215,9 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
if currentDetectedCount > maxDetectedCount {
session.stopRunning()

completedCallBack!(codeObject.stringValue)
if let stringValue = codeObject.stringValue {
completedCallBack?(stringValue)
}

if autoRemoveSubLayers {
removeAllLayers()
Expand Down Expand Up @@ -248,21 +255,21 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
shapeLayer.lineWidth = lineWidth
shapeLayer.strokeColor = strokeColor.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.path = createPath(codeObject.corners as NSArray).cgPath
shapeLayer.path = createPath(codeObject.corners).cgPath

drawLayer.addSublayer(shapeLayer)
}

func createPath(_ points: NSArray) -> UIBezierPath {
func createPath(_ points: [CGPoint]) -> UIBezierPath {
let path = UIBezierPath()

var point = CGPoint(dictionaryRepresentation: points[0] as! CFDictionary)
path.move(to: point!)
var point = points[0]
path.move(to: point)

var index = 1
while index < points.count {
point = CGPoint(dictionaryRepresentation: points[index] as! CFDictionary)
path.addLine(to: point!)
point = points[index]
path.addLine(to: point)

index = index + 1
}
Expand All @@ -274,8 +281,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
Expand All @@ -285,7 +292,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
Expand Down
Loading