Skip to content
Permalink
Browse files

Try mark swift classes/methods with @objc annotation

Add objc demo project
  • Loading branch information...
adrianmateoaea24 committed Feb 15, 2019
1 parent 41c6dfd commit 7e118cc89e6a2e138b551e659e689ef683688103

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -8,20 +8,20 @@
import UIKit

public class CKGridView: UIView {
@objc public class CKGridView: UIView {

public var color: UIColor = UIColor.white.withAlphaComponent(0.5) {
@objc public var color: UIColor = UIColor.white.withAlphaComponent(0.5) {
didSet {
self.setNeedsDisplay()
}
}

public override init(frame: CGRect) {
@objc public override init(frame: CGRect) {
super.init(frame: frame)
self.setupView()
}

public required init?(coder aDecoder: NSCoder) {
@objc public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupView()
}
@@ -6,9 +6,10 @@
// Copyright © 2019 Wonderkiln. All rights reserved.
//
import UIKit
import AVFoundation

extension CKPhotoSession.FlashMode {
extension CKSession.FlashMode {

var captureFlashMode: AVCaptureDevice.FlashMode {
switch self {
@@ -19,19 +20,15 @@ extension CKPhotoSession.FlashMode {
}
}

public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCaptureMetadataOutputObjectsDelegate {
@objc public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCaptureMetadataOutputObjectsDelegate {

public enum CameraDetection {
@objc public enum CameraDetection: UInt {
case none, faces
}

public enum FlashMode {
case off, on, auto
}

public typealias CaptureCallback = (UIImage?, AVCaptureResolvedPhotoSettings?, CKError?) -> Void

public var cameraPosition = CameraPosition.back {
@objc public var cameraPosition = CameraPosition.back {
didSet {
do {
let deviceInput = try CKSession.captureDeviceInput(type: self.cameraPosition.deviceType)
@@ -42,7 +39,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
}
}

public var cameraDetection = CameraDetection.none {
@objc public var cameraDetection = CameraDetection.none {
didSet {
if oldValue == self.cameraDetection { return }

@@ -67,7 +64,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
}
}

public var flashMode = FlashMode.off
@objc public var flashMode = CKSession.FlashMode.off

var captureDeviceInput: AVCaptureDeviceInput? {
didSet {
@@ -89,7 +86,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
var captureCallback: CaptureCallback?
var faceDetectionBoxes: [UIView] = []

public init(position: CameraPosition = .back, detection: CameraDetection = .none) {
@objc public init(position: CameraPosition = .back, detection: CameraDetection = .none) {
super.init()

defer {
@@ -101,10 +98,11 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
self.session.addOutput(self.photoOutput)
}

deinit {
@objc deinit {
self.faceDetectionBoxes.forEach({ $0.removeFromSuperview() })
}

// TODO: Fix mark as @objc
public func capture(_ callback: @escaping CaptureCallback) {
self.captureCallback = callback

@@ -114,11 +112,11 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
self.photoOutput.capturePhoto(with: settings, delegate: self)
}

public func togglePosition() {
@objc public func togglePosition() {
self.cameraPosition = self.cameraPosition == .back ? .front : .back
}

public override var zoom: Double {
@objc public override var zoom: Double {
didSet {
guard let device = self.captureDeviceInput?.device else {
return
@@ -138,6 +136,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
}
}

// TODO: Fix mark as @objc
public var resolution: CGSize? {
didSet {
guard let deviceInput = self.captureDeviceInput else {
@@ -163,7 +162,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
}
}

public override func focus(at point: CGPoint) {
@objc public override func focus(at point: CGPoint) {
if let device = self.captureDeviceInput?.device, device.isFocusPointOfInterestSupported {
do {
try device.lockForConfiguration()
@@ -177,7 +176,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
}

@available(iOS 11.0, *)
public func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
private func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {

guard let captureCallback = self.captureCallback else {
return
@@ -198,7 +197,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
self.processPhotoData(data: data, resolvedSettings: photo.resolvedSettings)
}

public func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
private func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {

guard let captureCallback = self.captureCallback else {
return
@@ -222,7 +221,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
self.processPhotoData(data: data, resolvedSettings: resolvedSettings)
}

func processPhotoData(data: Data, resolvedSettings: AVCaptureResolvedPhotoSettings) {
private func processPhotoData(data: Data, resolvedSettings: AVCaptureResolvedPhotoSettings) {
guard let captureCallback = self.captureCallback else {
return
}
@@ -243,7 +242,7 @@ public class CKPhotoSession: CKSession, AVCapturePhotoCaptureDelegate, AVCapture
captureCallback(image, resolvedSettings, nil)
}

public func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
private func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
let faceMetadataObjects = metadataObjects.filter({ $0.type == .face })

if faceMetadataObjects.count > self.faceDetectionBoxes.count {
@@ -9,11 +9,11 @@
import UIKit
import AVFoundation

public class CKPreviewView: UIView {
@objc public class CKPreviewView: UIView {

private var lastScale: CGFloat = 1.0

private(set) public var previewLayer: AVCaptureVideoPreviewLayer? {
@objc private(set) public var previewLayer: AVCaptureVideoPreviewLayer? {
didSet {
oldValue?.removeFromSuperlayer()

@@ -23,7 +23,7 @@ public class CKPreviewView: UIView {
}
}

public var session: CKSession? {
@objc public var session: CKSession? {
didSet {
oldValue?.stop()

@@ -36,6 +36,7 @@ public class CKPreviewView: UIView {
}
}

// TODO: Fix mark as @objc
private(set) public var gridView: CKGridView? {
didSet {
oldValue?.removeFromSuperview()
@@ -46,7 +47,7 @@ public class CKPreviewView: UIView {
}
}

public var showGrid: Bool = false {
@objc public var showGrid: Bool = false {
didSet {
if self.showGrid == oldValue {
return
@@ -60,12 +61,12 @@ public class CKPreviewView: UIView {
}
}

public override init(frame: CGRect) {
@objc public override init(frame: CGRect) {
super.init(frame: frame)
self.setupView()
}

public required init?(coder aDecoder: NSCoder) {
@objc public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupView()
}
@@ -51,50 +51,54 @@ extension CKSession.CameraPosition {
}
}

public protocol CKSessionDelegate: class {
func didChangeValue(session: CKSession, value: Any, key: String)
@objc public protocol CKSessionDelegate: class {
@objc func didChangeValue(session: CKSession, value: Any, key: String)
}

public class CKSession: NSObject {
@objc public class CKSession: NSObject {

public enum DeviceType {
@objc public enum DeviceType: UInt {
case frontCamera, backCamera, microphone
}

public enum CameraPosition {
@objc public enum CameraPosition: UInt {
case front, back
}

public let session: AVCaptureSession
@objc public enum FlashMode: UInt {
case off, on, auto
}

@objc public let session: AVCaptureSession

public var previewLayer: AVCaptureVideoPreviewLayer?
public var overlayView: UIView?
@objc public var previewLayer: AVCaptureVideoPreviewLayer?
@objc public var overlayView: UIView?

public var zoom = 1.0
@objc public var zoom = 1.0

public weak var delegate: CKSessionDelegate?
@objc public weak var delegate: CKSessionDelegate?

override init() {
@objc override init() {
self.session = AVCaptureSession()
}

deinit {
@objc deinit {
self.session.stopRunning()
}

public func start() {
@objc public func start() {
self.session.startRunning()
}

public func stop() {
@objc public func stop() {
self.session.stopRunning()
}

public func focus(at point: CGPoint) {
@objc public func focus(at point: CGPoint) {
//
}

public static func captureDeviceInput(type: DeviceType) throws -> AVCaptureDeviceInput {
@objc public static func captureDeviceInput(type: DeviceType) throws -> AVCaptureDeviceInput {
let captureDevices = AVCaptureDevice.DiscoverySession(
deviceTypes: [type.captureDeviceType],
mediaType: type.captureMediaType,
@@ -107,7 +111,7 @@ public class CKSession: NSObject {
return try AVCaptureDeviceInput(device: captureDevice)
}

public static func deviceInputFormat(input: AVCaptureDeviceInput, width: Int, height: Int, frameRate: Int = 30) -> AVCaptureDevice.Format? {
@objc public static func deviceInputFormat(input: AVCaptureDeviceInput, width: Int, height: Int, frameRate: Int = 30) -> AVCaptureDevice.Format? {
for format in input.device.formats {
let dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
if dimension.width >= width && dimension.height >= height {
@@ -8,9 +8,9 @@
import UIKit

public class CKUtils {
@objc public class CKUtils: NSObject {

public static func cropAndScale(_ image: UIImage, width: Int, height: Int) -> UIImage? {
@objc public static func cropAndScale(_ image: UIImage, width: Int, height: Int) -> UIImage? {
let fromRect = CGRect(x: 0, y: 0, width: image.size.height, height: image.size.width)
var toRect = CGRect(x: 0, y: 0, width: height, height: width)

Oops, something went wrong.

0 comments on commit 7e118cc

Please sign in to comment.
You can’t perform that action at this time.