Skip to content

Commit

Permalink
Run SwiftFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Oct 23, 2017
1 parent d2fa688 commit 519629c
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 186 deletions.
3 changes: 1 addition & 2 deletions Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
}

30 changes: 14 additions & 16 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class ViewController: UITableViewController {

captureController.delegate = self

for i in 0..<6 {
self.captureController.createAssetFromImage(UIImage(named: "hoff.jpeg")!) { asset in
for i in 0 ..< 6 {
captureController.createAssetFromImage(UIImage(named: "hoff.jpeg")!) { asset in
self.assets.append(asset)
self.tableView.insertRows(at: [IndexPath(row: i, section: 0)], with: .automatic)
}
Expand All @@ -26,16 +26,16 @@ class ViewController: UITableViewController {
tableView.reloadData()
}

@IBAction func addPhotosTapped(_ sender: AnyObject) {
@IBAction func addPhotosTapped(_: AnyObject) {
present(captureController, animated: true, completion: nil)
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
return assets.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
let asset = assets[indexPath.row]
cell.textLabel?.text = asset.UUID
cell.imageView?.image = nil
Expand All @@ -48,7 +48,6 @@ class ViewController: UITableViewController {
}
}


extension ViewController: PhotoCaptureViewControllerDelegate {
func photoCaptureViewController(_ controller: PhotoCaptureViewController, cellForItemAtIndexPath indexPath: IndexPath) -> PhotoCollectionViewCell? {
return controller.dequeuedReusableCellForClass(PhotoCollectionViewCell.self, indexPath: indexPath) { cell in
Expand All @@ -64,42 +63,41 @@ extension ViewController: PhotoCaptureViewControllerDelegate {
}
}

func photoCaptureViewControllerDidFinish(_ controller: PhotoCaptureViewController) {

func photoCaptureViewControllerDidFinish(_: PhotoCaptureViewController) {
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, didSelectAssetAtIndexPath indexPath: IndexPath) {
func photoCaptureViewController(_: PhotoCaptureViewController, didSelectAssetAtIndexPath indexPath: IndexPath) {
NSLog("tapped in \(indexPath.row)")
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, didFailWithError error: NSError) {
func photoCaptureViewController(_: PhotoCaptureViewController, didFailWithError error: NSError) {
NSLog("failure: \(error)")
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, didMoveItemFromIndexPath fromIndexPath: IndexPath, toIndexPath: IndexPath) {
func photoCaptureViewController(_: PhotoCaptureViewController, didMoveItemFromIndexPath fromIndexPath: IndexPath, toIndexPath: IndexPath) {
NSLog("moved from #\(fromIndexPath.item) to #\(toIndexPath.item)")
tableView.moveRow(at: fromIndexPath, to: toIndexPath)
}

func photoCaptureViewControllerNumberOfAssets(_ controller: PhotoCaptureViewController) -> Int {
func photoCaptureViewControllerNumberOfAssets(_: PhotoCaptureViewController) -> Int {
return assets.count
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, assetForIndexPath indexPath: IndexPath) -> Asset {
func photoCaptureViewController(_: PhotoCaptureViewController, assetForIndexPath indexPath: IndexPath) -> Asset {
return assets[indexPath.item]
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, didAddAsset asset: Asset) {
func photoCaptureViewController(_: PhotoCaptureViewController, didAddAsset asset: Asset) {
assets.append(asset)
tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, deleteAssetAtIndexPath indexPath: IndexPath) {
func photoCaptureViewController(_: PhotoCaptureViewController, deleteAssetAtIndexPath indexPath: IndexPath) {
assets.remove(at: indexPath.item)
tableView.deleteRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
}

func photoCaptureViewController(_ controller: PhotoCaptureViewController, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool {
func photoCaptureViewController(_: PhotoCaptureViewController, canMoveItemAtIndexPath _: IndexPath) -> Bool {
return true
}
}
2 changes: 1 addition & 1 deletion Finjinon/AssetResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal struct AssetResolver {
let queue = DispatchQueue(label: "com.finjinon.asset-resolvement", attributes: [])
var defaultTargetSize = CGSize(width: 720, height: 1280)

func enqueueResolve(_ asset: PHAsset, targetSize: CGSize? = nil, completion: @escaping (UIImage) -> Void) {
func enqueueResolve(_ asset: PHAsset, targetSize _: CGSize? = nil, completion: @escaping (UIImage) -> Void) {
queue.async {
self.resolve(asset, completion: completion)
}
Expand Down
12 changes: 6 additions & 6 deletions Finjinon/Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TriggerButton: UIButton {
setNeedsDisplay()
}
}

override var isEnabled: Bool {
didSet {
setNeedsDisplay()
Expand All @@ -22,15 +23,15 @@ class TriggerButton: UIButton {
backgroundColor = UIColor.clear
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func draw(_ dirtyRect: CGRect) {
super.draw(dirtyRect)

let length = min(bounds.width, bounds.height)
let outerRect = CGRect(x: (bounds.width/2)-(length/2), y: (bounds.height/2)-(length/2), width: length, height: length)
let outerRect = CGRect(x: (bounds.width / 2) - (length / 2), y: (bounds.height / 2) - (length / 2), width: length, height: length)
let borderWidth: CGFloat = 6.0
let outerPath = UIBezierPath(ovalIn: outerRect.insetBy(dx: borderWidth, dy: borderWidth))
outerPath.lineWidth = borderWidth
Expand All @@ -48,7 +49,6 @@ class TriggerButton: UIButton {
}
}


class CloseButton: UIButton {
var strokeColor = UIColor.black {
didSet { setNeedsDisplay() }
Expand All @@ -60,14 +60,14 @@ class CloseButton: UIButton {
backgroundColor = UIColor.lightGray.withAlphaComponent(0.9)
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()

layer.cornerRadius = bounds.height/2
layer.cornerRadius = bounds.height / 2
layer.masksToBounds = true
}

Expand All @@ -76,7 +76,7 @@ class CloseButton: UIButton {

// Draw a +
let centerPoint = CGPoint(x: bounds.midX, y: bounds.midY)
let radius: CGFloat = bounds.insetBy(dx: floor(bounds.width/8), dy: floor(bounds.width/8)).width / 2
let radius: CGFloat = bounds.insetBy(dx: floor(bounds.width / 8), dy: floor(bounds.width / 8)).width / 2
let ratio: CGFloat = 0.5
let xPath = UIBezierPath()
xPath.move(to: centerPoint)
Expand Down
30 changes: 15 additions & 15 deletions Finjinon/CaptureManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ enum CaptureManagerViewfinderMode {
class CaptureManager: NSObject {
let previewLayer: AVCaptureVideoPreviewLayer
var flashMode: AVCaptureFlashMode {
get {
return cameraDevice?.flashMode ?? .off
}
return cameraDevice?.flashMode ?? .off
}

var hasFlash: Bool {
return cameraDevice?.hasFlash ?? false && cameraDevice?.isFlashAvailable ?? false
}

var supportedFlashModes: [AVCaptureFlashMode] {
var modes: [AVCaptureFlashMode] = []
for mode in [AVCaptureFlashMode.off, AVCaptureFlashMode.auto, AVCaptureFlashMode.on] {
Expand All @@ -29,7 +29,8 @@ class CaptureManager: NSObject {
}
return modes
}
let viewfinderMode : CaptureManagerViewfinderMode

let viewfinderMode: CaptureManagerViewfinderMode

fileprivate let session = AVCaptureSession()
fileprivate let captureQueue = DispatchQueue(label: "no.finn.finjinon-captures", attributes: [])
Expand All @@ -39,7 +40,7 @@ class CaptureManager: NSObject {

override init() {
session.sessionPreset = AVCaptureSessionPresetPhoto
var viewfinderMode : CaptureManagerViewfinderMode {
var viewfinderMode: CaptureManagerViewfinderMode {
let screenBounds = UIScreen.main.nativeBounds
let ratio = screenBounds.height / screenBounds.width
return ratio <= 1.5 ? .fullScreen : .window
Expand Down Expand Up @@ -79,7 +80,7 @@ class CaptureManager: NSObject {
}
})
case .denied, .restricted:
completion(self.accessDeniedError())
completion(accessDeniedError())
}
}

Expand All @@ -99,7 +100,7 @@ class CaptureManager: NSObject {
}
connection.videoOrientation = self.orientation

self.stillImageOutput?.captureStillImageAsynchronously(from: connection, completionHandler: { (sampleBuffer, error) in
self.stillImageOutput?.captureStillImageAsynchronously(from: connection, completionHandler: { sampleBuffer, error in
if error == nil {
if let sampleBuffer = sampleBuffer, let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) {
if let metadata = CMCopyDictionaryOfAttachments(nil, sampleBuffer, CMAttachmentMode(kCMAttachmentMode_ShouldPropagate)) as NSDictionary? {
Expand All @@ -112,15 +113,15 @@ class CaptureManager: NSObject {
}
} else {
NSLog("Failed capturing still imagE: \(String(describing: error))")
// TODO
// TODO:
}
})
}
}

func lockFocusAtPointOfInterest(_ pointInLayer: CGPoint) {
let pointInCamera = previewLayer.captureDevicePointOfInterest(for: pointInLayer)
self.lockCurrentCameraDeviceForConfiguration { cameraDevice in
lockCurrentCameraDeviceForConfiguration { cameraDevice in
if let cameraDevice = self.cameraDevice, cameraDevice.isFocusPointOfInterestSupported {
cameraDevice.focusPointOfInterest = pointInCamera
cameraDevice.focusMode = .autoFocus
Expand Down Expand Up @@ -149,14 +150,14 @@ class CaptureManager: NSObject {
nextIndex = idx + 1
}
let startIndex = min(nextIndex, supportedFlashModes.count)
let next = supportedFlashModes[startIndex..<supportedFlashModes.count].first ?? supportedFlashModes.first
let next = supportedFlashModes[startIndex ..< supportedFlashModes.count].first ?? supportedFlashModes.first

return next
}

// Orientation change function required because we've locked the interface in portrait
// and DeviceOrientation does not map 1:1 with AVCaptureVideoOrientation
func changedOrientationNotification(_ notification: Notification?) {
func changedOrientationNotification(_: Notification?) {
let currentDeviceOrientation = UIDevice.current.orientation
switch currentDeviceOrientation {
case .faceDown, .faceUp, .unknown:
Expand Down Expand Up @@ -201,7 +202,7 @@ class CaptureManager: NSObject {
if self.session.canAddInput(input) {
self.session.addInput(input)
} else {
// TODO handle?
// TODO: handle?
NSLog("failed to add input \(input) to session \(self.session)")
}
} catch let error1 as NSError {
Expand All @@ -211,15 +212,14 @@ class CaptureManager: NSObject {

self.stillImageOutput = AVCaptureStillImageOutput()
self.stillImageOutput?.outputSettings = [
AVVideoCodecKey : AVVideoCodecJPEG,
AVVideoQualityKey: 0.9
AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoQualityKey: 0.9,
]

if self.session.canAddOutput(self.stillImageOutput) {
self.session.addOutput(self.stillImageOutput)
}


if let cameraDevice = self.cameraDevice {
if cameraDevice.isFocusModeSupported(.continuousAutoFocus) {
do {
Expand Down
9 changes: 4 additions & 5 deletions Finjinon/ImagePickerAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ public protocol ImagePickerAdapter {
func viewControllerForImageSelection(_ selectedAssetsHandler: @escaping ([PHAsset]) -> Void, completion: @escaping (Bool) -> Void) -> UIViewController
}


open class ImagePickerControllerAdapter: NSObject, ImagePickerAdapter, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

var selectionHandler: ([PHAsset]) -> Void = { _ in }
var completionHandler: (_ didCancel: Bool) -> Void = { _ in }

open func viewControllerForImageSelection(_ selectedAssetsHandler: @escaping ([PHAsset]) -> Void, completion: @escaping (Bool) -> Void) -> UIViewController {
self.selectionHandler = selectedAssetsHandler
self.completionHandler = completion
selectionHandler = selectedAssetsHandler
completionHandler = completion

let picker = UIImagePickerController()
picker.mediaTypes = [kUTTypeImage as String]
Expand All @@ -32,7 +31,7 @@ open class ImagePickerControllerAdapter: NSObject, ImagePickerAdapter, UIImagePi
return picker
}

open func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
open func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
guard let referenceURL = info[UIImagePickerControllerReferenceURL] as? URL else {
completionHandler(true)
return
Expand All @@ -48,7 +47,7 @@ open class ImagePickerControllerAdapter: NSObject, ImagePickerAdapter, UIImagePi
}
}

open func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
open func imagePickerControllerDidCancel(_: UIImagePickerController) {
completionHandler(true)
}
}
Loading

0 comments on commit 519629c

Please sign in to comment.