Skip to content

Commit

Permalink
Merge pull request hyperoslo#335 from autumnssun/swift4
Browse files Browse the repository at this point in the history
Swift 4
  • Loading branch information
onmyway133 authored Oct 4, 2017
2 parents 8f7952b + 0315003 commit 611f205
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 57 deletions.
28 changes: 20 additions & 8 deletions ImagePicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Hyper Interaktiv AS";
TargetAttributes = {
D5DC598A1C201BE1003BD79B = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = QQJ8AA32HJ;
DevelopmentTeam = 9J5NKKT78R;
LastSwiftMigration = 0800;
};
D5DC59941C201BE1003BD79B = {
Expand Down Expand Up @@ -397,14 +397,20 @@
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_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_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;
Expand All @@ -428,7 +434,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -447,14 +453,20 @@
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_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_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;
Expand All @@ -472,7 +484,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -488,7 +500,7 @@
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = QQJ8AA32HJ;
DEVELOPMENT_TEAM = 9J5NKKT78R;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -499,7 +511,7 @@
PRODUCT_BUNDLE_IDENTIFIER = no.hyper.ImagePicker;
PRODUCT_NAME = ImagePicker;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -508,7 +520,7 @@
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = QQJ8AA32HJ;
DEVELOPMENT_TEAM = 9J5NKKT78R;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -519,7 +531,7 @@
PRODUCT_BUNDLE_IDENTIFIER = no.hyper.ImagePicker;
PRODUCT_NAME = ImagePicker;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
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 = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
6 changes: 3 additions & 3 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ open class BottomContainerView: UIView {

// MARK: - Action methods

func doneButtonDidPress(_ button: UIButton) {
@objc func doneButtonDidPress(_ button: UIButton) {
if button.currentTitle == configuration.cancelButtonTitle {
delegate?.cancelButtonDidPress()
} else {
delegate?.doneButtonDidPress()
}
}

func handleTapGestureRecognizer(_ recognizer: UITapGestureRecognizer) {
@objc func handleTapGestureRecognizer(_ recognizer: UITapGestureRecognizer) {
delegate?.imageStackViewDidPress()
}

Expand All @@ -110,7 +110,7 @@ open class BottomContainerView: UIView {
UIView.animate(withDuration: 0.3, animations: {
imageView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
}, completion: { _ in
UIView.animate(withDuration: 0.2, animations: { _ in
UIView.animate(withDuration: 0.2, animations: {
imageView.transform = CGAffineTransform.identity
})
})
Expand Down
6 changes: 3 additions & 3 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ class ButtonPicker: UIButton {

// MARK: - Actions

func recalculatePhotosCount(_ notification: Notification) {
@objc func recalculatePhotosCount(_ notification: Notification) {
guard let sender = notification.object as? ImageStack else { return }
numberLabel.text = sender.assets.isEmpty ? "" : String(sender.assets.count)
}

func pickerButtonDidPress(_ button: UIButton) {
@objc func pickerButtonDidPress(_ button: UIButton) {
backgroundColor = UIColor.white
numberLabel.textColor = UIColor.black
numberLabel.sizeToFit()
delegate?.buttonDidPress()
}

func pickerButtonDidHighlight(_ button: UIButton) {
@objc func pickerButtonDidHighlight(_ button: UIButton) {
numberLabel.textColor = UIColor.white
backgroundColor = UIColor(red:0.3, green:0.3, blue:0.3, alpha:1)
}
Expand Down
6 changes: 3 additions & 3 deletions Source/BottomView/StackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ImageStackView: UIView {

extension ImageStackView {

func imageDidPush(_ notification: Notification) {
@objc func imageDidPush(_ notification: Notification) {
let emptyView = views.filter { $0.image == nil }.first

if let emptyView = emptyView {
Expand All @@ -118,14 +118,14 @@ extension ImageStackView {
}
}

func imageStackDidChangeContent(_ notification: Notification) {
@objc func imageStackDidChangeContent(_ notification: Notification) {
if let sender = notification.object as? ImageStack {
renderViews(sender.assets)
activityView.stopAnimating()
}
}

func renderViews(_ assets: [PHAsset]) {
@objc func renderViews(_ assets: [PHAsset]) {
if let firstView = views.first, assets.isEmpty {
views.forEach {
$0.image = nil
Expand Down
24 changes: 12 additions & 12 deletions Source/CameraView/CameraMan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CameraMan {
.devices().flatMap {
return $0 as? AVCaptureDevice
}.filter {
return $0.hasMediaType(AVMediaTypeVideo)
return $0.hasMediaType(AVMediaType.video)
}.forEach {
switch $0.position {
case .front:
Expand Down Expand Up @@ -68,7 +68,7 @@ class CameraMan {
// MARK: - Permission

func checkPermission() {
let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)

switch status {
case .authorized:
Expand All @@ -81,7 +81,7 @@ class CameraMan {
}

func requestPermission() {
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { granted in
AVCaptureDevice.requestAccess(for: AVMediaType.video) { granted in
DispatchQueue.main.async {
if granted {
self.start()
Expand Down Expand Up @@ -151,7 +151,7 @@ class CameraMan {
}

func takePhoto(_ previewLayer: AVCaptureVideoPreviewLayer, location: CLLocation?, completion: (() -> Void)? = nil) {
guard let connection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo) else { return }
guard let connection = stillImageOutput?.connection(with: AVMediaType.video) else { return }

connection.videoOrientation = Helper.videoOrientation()

Expand All @@ -177,14 +177,14 @@ class CameraMan {
let request = PHAssetChangeRequest.creationRequestForAsset(from: image)
request.creationDate = Date()
request.location = location
}, completionHandler: { _ in
}, completionHandler: { (ok,error) in
DispatchQueue.main.async {
completion?()
}
})
}

func flash(_ mode: AVCaptureFlashMode) {
func flash(_ mode: AVCaptureDevice.FlashMode) {
guard let device = currentInput?.device, device.isFlashModeSupported(mode) else { return }

queue.async {
Expand All @@ -195,7 +195,7 @@ class CameraMan {
}

func focus(_ point: CGPoint) {
guard let device = currentInput?.device, device.isFocusModeSupported(AVCaptureFocusMode.locked) else { return }
guard let device = currentInput?.device, device.isFocusModeSupported(AVCaptureDevice.FocusMode.locked) else { return }

queue.async {
self.lock {
Expand Down Expand Up @@ -234,18 +234,18 @@ class CameraMan {

func configurePreset(_ input: AVCaptureDeviceInput) {
for asset in preferredPresets() {
if input.device.supportsAVCaptureSessionPreset(asset) && self.session.canSetSessionPreset(asset) {
self.session.sessionPreset = asset
if input.device.supportsSessionPreset(AVCaptureSession.Preset(rawValue: asset)) && self.session.canSetSessionPreset(AVCaptureSession.Preset(rawValue: asset)) {
self.session.sessionPreset = AVCaptureSession.Preset(rawValue: asset)
return
}
}
}

func preferredPresets() -> [String] {
return [
AVCaptureSessionPresetHigh,
AVCaptureSessionPresetMedium,
AVCaptureSessionPresetLow
AVCaptureSession.Preset.high.rawValue,
AVCaptureSession.Preset.high.rawValue,
AVCaptureSession.Preset.low.rawValue
]
}
}
24 changes: 12 additions & 12 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
let button = UIButton(type: .system)
let title = NSAttributedString(string: self.configuration.settingsTitle,
attributes: [
NSFontAttributeName: self.configuration.settingsFont,
NSForegroundColorAttributeName: self.configuration.settingsColor
NSAttributedStringKey.font: self.configuration.settingsFont,
NSAttributedStringKey.foregroundColor: self.configuration.settingsColor
])

button.setAttributedTitle(title, for: UIControlState())
Expand Down Expand Up @@ -142,7 +142,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

previewLayer?.connection.videoOrientation = .portrait
previewLayer?.connection?.videoOrientation = .portrait
locationManager?.startUpdatingLocation()
}

Expand All @@ -152,11 +152,11 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
}

func setupPreviewLayer() {
guard let layer = AVCaptureVideoPreviewLayer(session: cameraMan.session) else { return }
let layer = AVCaptureVideoPreviewLayer(session: cameraMan.session)

layer.backgroundColor = configuration.mainColor.cgColor
layer.autoreverses = true
layer.videoGravity = AVLayerVideoGravityResizeAspectFill
layer.videoGravity = AVLayerVideoGravity.resizeAspectFill

view.layer.insertSublayer(layer, at: 0)
layer.frame = view.layer.frame
Expand Down Expand Up @@ -185,7 +185,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate

// MARK: - Actions

func settingsButtonDidTap() {
@objc func settingsButtonDidTap() {
DispatchQueue.main.async {
if let settingsURL = URL(string: UIApplicationOpenSettingsURLString) {
UIApplication.shared.openURL(settingsURL)
Expand All @@ -196,7 +196,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
// MARK: - Camera actions

func rotateCamera() {
UIView.animate(withDuration: 0.3, animations: { _ in
UIView.animate(withDuration: 0.3, animations: {
self.containerView.alpha = 1
}, completion: { _ in
self.cameraMan.switchCamera {
Expand All @@ -208,7 +208,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
}

func flashCamera(_ title: String) {
let mapping: [String: AVCaptureFlashMode] = [
let mapping: [String: AVCaptureDevice.FlashMode] = [
"ON": .on,
"OFF": .off
]
Expand All @@ -235,7 +235,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate

// MARK: - Timer methods

func timerDidFire() {
@objc func timerDidFire() {
UIView.animate(withDuration: 0.3, animations: { [unowned self] in
self.focusImageView.alpha = 0
}, completion: { _ in
Expand All @@ -252,7 +252,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
cameraMan.focus(convertedPoint)

focusImageView.center = point
UIView.animate(withDuration: 0.5, animations: { _ in
UIView.animate(withDuration: 0.5, animations: {
self.focusImageView.alpha = 1
self.focusImageView.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
}, completion: { _ in
Expand All @@ -273,7 +273,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate

// MARK: - Tap

func tapGestureRecognizerHandler(_ gesture: UITapGestureRecognizer) {
@objc func tapGestureRecognizerHandler(_ gesture: UITapGestureRecognizer) {
let touch = gesture.location(in: view)

focusImageView.transform = CGAffineTransform.identity
Expand All @@ -283,7 +283,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate

// MARK: - Pinch

func pinchGestureRecognizerHandler(_ gesture: UIPinchGestureRecognizer) {
@objc func pinchGestureRecognizerHandler(_ gesture: UIPinchGestureRecognizer) {
switch gesture.state {
case .began:
fallthrough
Expand Down
Loading

0 comments on commit 611f205

Please sign in to comment.