Skip to content

Support loading assets from Package. #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions InAppViewDebugger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -124,6 +125,7 @@
03A42842225703C500A5242D /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
03A4284422570DFE00A5242D /* InAppViewDebugger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppViewDebugger.swift; sourceTree = "<group>"; };
03A42846225710CF00A5242D /* ViewControllerUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerUtils.swift; sourceTree = "<group>"; };
952A05D024BE2405004DB00D /* Bundle+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Extension.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -192,6 +194,7 @@
034CC48E2251A1ED00953FC3 /* InAppViewDebugger */ = {
isa = PBXGroup;
children = (
952A05D024BE2405004DB00D /* Bundle+Extension.swift */,
034CC48F2251A1ED00953FC3 /* InAppViewDebugger.h */,
034CC4902251A1ED00953FC3 /* Info.plist */,
03A4283C225481CD00A5242D /* Assets.xcassets */,
Expand Down Expand Up @@ -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 */,
Expand Down
43 changes: 43 additions & 0 deletions InAppViewDebugger/Bundle+Extension.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}
5 changes: 4 additions & 1 deletion InAppViewDebugger/RangeSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import PackageDescription
let package = Package(
name: "InAppViewDebugger",
platforms: [
.iOS(.v13),
.watchOS(.v6)
.iOS(.v14),
.watchOS(.v7)
],
products: [
.library(
Expand Down