Skip to content

Commit

Permalink
Add SPM support (#24)
Browse files Browse the repository at this point in the history
* Add the package manifest

* Load resources in the module

* Remove redundant settings
  • Loading branch information
woxtu authored Nov 30, 2020
1 parent f79f5e1 commit 9c81351
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "QRScanner",
platforms: [
.iOS(.v10),
],
products: [
.library(
name: "QRScanner",
targets: ["QRScanner"]
),
],
dependencies: [],
targets: [
.target(
name: "QRScanner",
dependencies: [],
path: "QRScanner",
exclude: [
"Info.plist",
]
),
]
)
4 changes: 4 additions & 0 deletions QRScanner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
16A16407235712360032684C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16A16406235712360032684C /* Images.xcassets */; };
16D0D5EE23570BC800A2EC78 /* QRScanner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16D0D5E423570BC800A2EC78 /* QRScanner.framework */; };
16D0D5F523570BC800A2EC78 /* QRScanner.h in Headers */ = {isa = PBXBuildFile; fileRef = 16D0D5E723570BC800A2EC78 /* QRScanner.h */; settings = {ATTRIBUTES = (Public, ); }; };
43820BFF256A29DD0046AC78 /* Bundle+Module.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43820BFE256A29DD0046AC78 /* Bundle+Module.swift */; };
76124403238BCEA70020466C /* QRScannerViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76124402238BCEA70020466C /* QRScannerViewTests.swift */; };
76E80674238BB26E0000C667 /* QRScannerSpyDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76E80673238BB26E0000C667 /* QRScannerSpyDelegate.swift */; };
/* End PBXBuildFile section */
Expand All @@ -35,6 +36,7 @@
16D0D5E823570BC800A2EC78 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
16D0D5ED23570BC800A2EC78 /* QRScannerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QRScannerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
16D0D5F423570BC800A2EC78 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
43820BFE256A29DD0046AC78 /* Bundle+Module.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Module.swift"; sourceTree = "<group>"; };
76124402238BCEA70020466C /* QRScannerViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRScannerViewTests.swift; sourceTree = "<group>"; };
76E80673238BB26E0000C667 /* QRScannerSpyDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRScannerSpyDelegate.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -80,6 +82,7 @@
isa = PBXGroup;
children = (
16D0D5E723570BC800A2EC78 /* QRScanner.h */,
43820BFE256A29DD0046AC78 /* Bundle+Module.swift */,
16A16402235710D80032684C /* QRScannerView.swift */,
16A16404235711240032684C /* QRScannerError.swift */,
16D0D5E823570BC800A2EC78 /* Info.plist */,
Expand Down Expand Up @@ -227,6 +230,7 @@
files = (
16A16405235711240032684C /* QRScannerError.swift in Sources */,
16A16403235710D80032684C /* QRScannerView.swift in Sources */,
43820BFF256A29DD0046AC78 /* Bundle+Module.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
16 changes: 16 additions & 0 deletions QRScanner/Bundle+Module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Bundle+Module.swift
// QRScanner
//
// Created by woxtu on 2020/11/22.
//

import Foundation

#if !SWIFT_PACKAGE
extension Bundle {
static var module: Bundle = {
return Bundle(for: QRScannerView.self)
}()
}
#endif
2 changes: 1 addition & 1 deletion QRScanner/QRScannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public class QRScannerView: UIView {
let x = self.bounds.width * 0.191
let y = self.bounds.height * 0.191
focusImageView = UIImageView(frame: CGRect(x: x, y: y, width: width, height: width))
focusImageView.image = focusImage ?? UIImage(named: "scan_qr_focus", in: Bundle(for: QRScannerView.self), compatibleWith: nil)
focusImageView.image = focusImage ?? UIImage(named: "scan_qr_focus", in: .module, compatibleWith: nil)
addSubview(focusImageView)

qrCodeImageView = UIImageView()
Expand Down

0 comments on commit 9c81351

Please sign in to comment.