diff --git a/InAppViewDebugger.xcodeproj/project.pbxproj b/InAppViewDebugger.xcodeproj/project.pbxproj index 525bf2b..356a95d 100644 --- a/InAppViewDebugger.xcodeproj/project.pbxproj +++ b/InAppViewDebugger.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 03A42843225703C500A5242D /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A42842225703C500A5242D /* Configuration.swift */; }; 03A4284522570DFE00A5242D /* InAppViewDebugger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A4284422570DFE00A5242D /* InAppViewDebugger.swift */; }; 03A42847225710CF00A5242D /* ViewControllerUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A42846225710CF00A5242D /* ViewControllerUtils.swift */; }; + 952A05D124BE2405004DB00D /* Bundle+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952A05D024BE2405004DB00D /* Bundle+Extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -124,6 +125,7 @@ 03A42842225703C500A5242D /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; 03A4284422570DFE00A5242D /* InAppViewDebugger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppViewDebugger.swift; sourceTree = ""; }; 03A42846225710CF00A5242D /* ViewControllerUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerUtils.swift; sourceTree = ""; }; + 952A05D024BE2405004DB00D /* Bundle+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Extension.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -192,6 +194,7 @@ 034CC48E2251A1ED00953FC3 /* InAppViewDebugger */ = { isa = PBXGroup; children = ( + 952A05D024BE2405004DB00D /* Bundle+Extension.swift */, 034CC48F2251A1ED00953FC3 /* InAppViewDebugger.h */, 034CC4902251A1ED00953FC3 /* Info.plist */, 03A4283C225481CD00A5242D /* Assets.xcassets */, @@ -388,6 +391,7 @@ buildActionMask = 2147483647; files = ( 034CC4BB2251EA0000953FC3 /* SnapshotView.swift in Sources */, + 952A05D124BE2405004DB00D /* Bundle+Extension.swift in Sources */, 034CC49A2251A22200953FC3 /* Element.swift in Sources */, 03A42847225710CF00A5242D /* ViewControllerUtils.swift in Sources */, 034CC4B92251E8D800953FC3 /* Snapshot.swift in Sources */, diff --git a/InAppViewDebugger/Bundle+Extension.swift b/InAppViewDebugger/Bundle+Extension.swift new file mode 100644 index 0000000..0792f1b --- /dev/null +++ b/InAppViewDebugger/Bundle+Extension.swift @@ -0,0 +1,43 @@ +// +// Bundle+Extension.swift +// +// +// Created by Robert Powell on 7/14/20. +// + +import Foundation + +extension Bundle { + /// Returns a bundle for a class or from a package included from Swift Package Manager + /// + /// This initializer makes use of some details from an Xcode beta that may be subject to change. + /// Do not use this initializer for classes that are defined in your application. + /// + /// Parameters: + /// -aClass: A class + /// -package: The name of the directory that corresponds to your framework included by Swift Package Manager. + public convenience init?(for aClass: AnyClass, in package: String) { + let bundle: Bundle? + + let mysteryBundle = Bundle(for: aClass) + if let location = mysteryBundle.bundlePath.range(of: ".app"), + location.upperBound == mysteryBundle.bundlePath.endIndex { + //Runtime has returned the main Bundle, not the framework bundle + //Runtime has returned the main Bundle, not the framework bundle + if let path = mysteryBundle.path(forResource: package, ofType: "bundle") { + bundle = Bundle(path: path) + } else { + assert(false, "A nonexistent package was specified. Check \(mysteryBundle.bundlePath) for correct name of package") + bundle = nil + } + } else { + bundle = mysteryBundle + } + + if let path = bundle?.bundlePath { + self.init(path: path) + } else { + return nil + } + } +} diff --git a/InAppViewDebugger/RangeSlider.swift b/InAppViewDebugger/RangeSlider.swift index 5549738..a58892a 100644 --- a/InAppViewDebugger/RangeSlider.swift +++ b/InAppViewDebugger/RangeSlider.swift @@ -215,7 +215,10 @@ final class RangeSlider: UIControl { } private func imageNamed(_ name: String) -> UIImage? { - return UIImage(named: name, in: Bundle(for: RangeSlider.self), compatibleWith: nil) + let bundle = Bundle(for: RangeSlider.self, in: "InAppViewDebugger_InAppViewDebugger") + let image = UIImage(named: name, in: bundle, compatibleWith: nil) + assert(image != nil) + return image } private func trackImage() -> UIImage? { diff --git a/Package.swift b/Package.swift index 7937007..386df30 100644 --- a/Package.swift +++ b/Package.swift @@ -5,8 +5,8 @@ import PackageDescription let package = Package( name: "InAppViewDebugger", platforms: [ - .iOS(.v13), - .watchOS(.v6) + .iOS(.v14), + .watchOS(.v7) ], products: [ .library(