From e9931852b9d6d435f3d6d2ed6bfe5dab67a0de4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20G=C3=BCnd=C3=BCz?= Date: Fri, 24 May 2024 14:54:24 +0200 Subject: [PATCH] Add support for adding this lib to multi-platform targets where only used for iOS --- Package.swift | 28 ++++--------------- ...AVCaptureDevice+bestForBuiltInCamera.swift | 2 ++ Sources/CodeScanner/CodeScanner.swift | 2 ++ .../CodeScanner/ScannerViewController.swift | 2 ++ 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Package.swift b/Package.swift index 377f4ef..42076e9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,28 +1,10 @@ -// swift-tools-version:5.3 -// The swift-tools-version declares the minimum version of Swift required to build this package. - +// swift-tools-version:5.9 import PackageDescription let package = Package( name: "CodeScanner", - platforms: [ - .iOS(.v13) - ], - products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. - .library( - name: "CodeScanner", - targets: ["CodeScanner"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target( - name: "CodeScanner", - dependencies: []), - ] + platforms: [.iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .visionOS(.v1), .watchOS(.v6)], + products: [.library(name: "CodeScanner", targets: ["CodeScanner"])], + dependencies: [], + targets: [.target(name: "CodeScanner", dependencies: [])] ) diff --git a/Sources/CodeScanner/AVCaptureDevice+bestForBuiltInCamera.swift b/Sources/CodeScanner/AVCaptureDevice+bestForBuiltInCamera.swift index 2c1b8f7..0a088c3 100644 --- a/Sources/CodeScanner/AVCaptureDevice+bestForBuiltInCamera.swift +++ b/Sources/CodeScanner/AVCaptureDevice+bestForBuiltInCamera.swift @@ -6,6 +6,7 @@ // Copyright © 2024 Paul Hudson. All rights reserved. // +#if os(iOS) import AVFoundation @available(macCatalyst 14.0, *) @@ -79,6 +80,7 @@ private extension Float { self * Float.pi / 180 } } +#endif /* Part of this code is copied from Apple sample project "AVCamBarcode: Using AVFoundation to capture barcodes". diff --git a/Sources/CodeScanner/CodeScanner.swift b/Sources/CodeScanner/CodeScanner.swift index cffaf83..85b7994 100644 --- a/Sources/CodeScanner/CodeScanner.swift +++ b/Sources/CodeScanner/CodeScanner.swift @@ -6,6 +6,7 @@ // Copyright © 2021 Paul Hudson. All rights reserved. // +#if os(iOS) import AVFoundation import SwiftUI @@ -153,3 +154,4 @@ struct CodeScannerView_Previews: PreviewProvider { } } } +#endif diff --git a/Sources/CodeScanner/ScannerViewController.swift b/Sources/CodeScanner/ScannerViewController.swift index f12e993..87930cb 100644 --- a/Sources/CodeScanner/ScannerViewController.swift +++ b/Sources/CodeScanner/ScannerViewController.swift @@ -6,6 +6,7 @@ // Copyright © 2021 Paul Hudson. All rights reserved. // +#if os(iOS) import AVFoundation import UIKit @@ -594,3 +595,4 @@ public extension AVCaptureDevice { } } +#endif