Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 45d461f

Browse files
committed
Fixed protection level
1 parent 7ecae68 commit 45d461f

File tree

4 files changed

+39
-41
lines changed

4 files changed

+39
-41
lines changed

Sources/ScanKit/NSCodeScanner.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ import OSLog
3232

3333
fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "dev.fromshawn.scankit", category: "ScanKit")
3434

35-
struct ScanKitPreview: NSViewControllerRepresentable {
35+
public struct ScanKitPreview: NSViewControllerRepresentable {
3636
var camera: ScanKitCamera
3737

38-
init(camera: ScanKitCamera, startScanningOnLoad: Bool = true) {
38+
public init(camera: ScanKitCamera, startScanningOnLoad: Bool = true) {
3939
self.camera = camera
4040
}
4141

42-
func makeNSViewController(context: Context) -> NSCodeScanner {
42+
public func makeNSViewController(context: Context) -> NSCodeScanner {
4343
return NSCodeScanner(camera: camera)
4444
}
4545

46-
func updateNSViewController(_ nsViewController: NSCodeScanner, context: Context) {
46+
public func updateNSViewController(_ nsViewController: NSCodeScanner, context: Context) {
4747
// do nothing
4848
}
4949
}
5050

51-
class NSCodeScanner: NSViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
51+
public class NSCodeScanner: NSViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
5252

5353
weak var camera: ScanKitCamera?
5454

@@ -61,12 +61,12 @@ class NSCodeScanner: NSViewController, AVCaptureVideoDataOutputSampleBufferDeleg
6161
fatalError("init(coder:) has not been implemented")
6262
}
6363

64-
override func loadView() {
64+
public override func loadView() {
6565
view = NSView(frame: .zero)
6666
view.layerContentsRedrawPolicy = .crossfade
6767
}
6868

69-
override func viewDidLoad() {
69+
public override func viewDidLoad() {
7070
super.viewDidLoad()
7171

7272
addPreviewLayer()
@@ -77,12 +77,12 @@ class NSCodeScanner: NSViewController, AVCaptureVideoDataOutputSampleBufferDeleg
7777
}
7878
}
7979

80-
override func viewWillDisappear() {
80+
public override func viewWillDisappear() {
8181
super.viewWillDisappear()
8282
camera?.stop()
8383
}
8484

85-
override func viewWillLayout() {
85+
public override func viewWillLayout() {
8686
super.viewWillLayout()
8787
self.camera?.previewLayer.frame = self.view.bounds
8888
}

Sources/ScanKit/ScanKit.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import OSLog
3232
/// A drop-in code symbology scanner.
3333
public struct ScannerView: View {
3434
let showViewfinder: Bool
35-
let completion: (Result<String, ScanKitCamera.ScanKitError>) -> ()
35+
let completion: (Result<String, ScanKitError>) -> ()
3636
@Binding var scanning: Bool
3737
@StateObject var camera = ScanKitCamera()
3838

@@ -59,10 +59,10 @@ public struct ScannerView: View {
5959
/// When `false` the preview will continue but frames will not be processed for
6060
/// instances of the selected symbology.
6161
/// - completion: A completion handler that returns a `Result` of either `String` when information has been found and can be decoded or `ScanKitError` when an error occurs.
62-
init(for symbology: VNBarcodeSymbology,
62+
public init(for symbology: VNBarcodeSymbology,
6363
showViewfinder: Bool = true,
6464
isScanning: Binding<Bool>,
65-
completion: @escaping (Result<String, ScanKitCamera.ScanKitError>) -> Void) {
65+
completion: @escaping (Result<String, ScanKitError>) -> Void) {
6666
self.showViewfinder = showViewfinder
6767
self.completion = completion
6868
self._scanning = isScanning
@@ -84,7 +84,7 @@ public struct ScannerView: View {
8484
completion(.success(result))
8585
}
8686
} catch let error {
87-
completion(.failure(error as! ScanKitCamera.ScanKitError))
87+
completion(.failure(error as! ScanKitError))
8888
}
8989
}
9090
}
@@ -99,7 +99,7 @@ public struct ScannerView: View {
9999
completion(.success(result))
100100
}
101101
} catch let error {
102-
completion(.failure(error as! ScanKitCamera.ScanKitError))
102+
completion(.failure(error as! ScanKitError))
103103
}
104104
}
105105
}
@@ -114,7 +114,7 @@ public struct ScannerView: View {
114114
completion(.success(result))
115115
}
116116
} catch let error {
117-
completion(.failure(error as! ScanKitCamera.ScanKitError))
117+
completion(.failure(error as! ScanKitError))
118118
}
119119
}
120120
}
@@ -207,3 +207,17 @@ public class ScanKit {
207207
return results
208208
}
209209
}
210+
211+
/// Possible ScanKitCamera errors to throw.
212+
public enum ScanKitError: Error, LocalizedError {
213+
case visionFailed, notAuthorized
214+
215+
public var errorDescription: String? {
216+
switch self {
217+
case .visionFailed:
218+
return "ScanKit failed to intiailize the scanner."
219+
case .notAuthorized:
220+
return "ScanKit was unable to access the camera."
221+
}
222+
}
223+
}

Sources/ScanKit/ScanKitCamera.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Combine
3131

3232
fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "dev.fromshawn.scankit", category: "ScanKitCamera")
3333

34-
class ScanKitCamera: NSObject, ObservableObject, AVCaptureVideoDataOutputSampleBufferDelegate {
34+
public class ScanKitCamera: NSObject, ObservableObject, AVCaptureVideoDataOutputSampleBufferDelegate {
3535
private let captureSession = AVCaptureSession()
3636
private var isCaptureSessionConfigured: Bool = false
3737
weak private var deviceInput: AVCaptureDeviceInput?
@@ -373,7 +373,7 @@ class ScanKitCamera: NSObject, ObservableObject, AVCaptureVideoDataOutputSampleB
373373
}
374374

375375
/// A method of `AVCaptureVideoDataOutputSampleBufferDelegate` that, for the purposes of this class, processes `Vision` requests.
376-
internal func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
376+
public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
377377
// Only process every tenth frame when scanning is true
378378
visionIterator += 1
379379
guard (visionIterator % 10 == 0), isScanning else { return }
@@ -437,20 +437,4 @@ class ScanKitCamera: NSObject, ObservableObject, AVCaptureVideoDataOutputSampleB
437437
}
438438
}
439439
}
440-
441-
// MARK: - Error Handling
442-
443-
/// Possible ScanKitCamera errors to throw.
444-
enum ScanKitError: Error, LocalizedError {
445-
case visionFailed, notAuthorized
446-
447-
var errorDescription: String? {
448-
switch self {
449-
case .visionFailed:
450-
return "ScanKit failed to intiailize the scanner."
451-
case .notAuthorized:
452-
return "ScanKit was unable to access the camera."
453-
}
454-
}
455-
}
456440
}

Sources/ScanKit/UICodeScanner.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "dev.
3434

3535
//TODO: Decouple model from UIViewController :(
3636

37-
struct ScanKitPreview: UIViewControllerRepresentable {
37+
public struct ScanKitPreview: UIViewControllerRepresentable {
3838
var camera: ScanKitCamera
3939

40-
init(camera: ScanKitCamera) {
40+
public init(camera: ScanKitCamera) {
4141
self.camera = camera
4242
}
4343

44-
func makeUIViewController(context: Context) -> UICodeScanner {
44+
public func makeUIViewController(context: Context) -> UICodeScanner {
4545
return UICodeScanner(camera: camera)
4646
}
4747

48-
func updateUIViewController(_ uiViewController: UICodeScanner, context: Context) {
48+
public func updateUIViewController(_ uiViewController: UICodeScanner, context: Context) {
4949
// Do nothing!
5050
}
5151
}
5252

53-
class UICodeScanner: UIViewController {
53+
public class UICodeScanner: UIViewController {
5454
weak var camera: ScanKitCamera?
5555

5656
private var deviceOrientation: UIDeviceOrientation {
@@ -70,7 +70,7 @@ class UICodeScanner: UIViewController {
7070
fatalError("init(coder:) has not been implemented")
7171
}
7272

73-
override func viewDidLoad() {
73+
public override func viewDidLoad() {
7474
super.viewDidLoad()
7575
addPreviewLayer()
7676

@@ -80,12 +80,12 @@ class UICodeScanner: UIViewController {
8080
}
8181
}
8282

83-
override func viewWillDisappear(_ animated: Bool) {
83+
public override func viewWillDisappear(_ animated: Bool) {
8484
super.viewWillDisappear(animated)
8585
camera?.stop()
8686
}
8787

88-
override func viewDidLayoutSubviews() {
88+
public override func viewDidLayoutSubviews() {
8989
super.viewDidLayoutSubviews()
9090

9191
// Update video orientation on rotate

0 commit comments

Comments
 (0)