Skip to content

Commit

Permalink
♻️ Update bundle handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Jan 26, 2022
1 parent 88b49a0 commit 7a24d46
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Examples/DeveloperCocoapodsExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../../Appcues.podspec"

SPEC CHECKSUMS:
Appcues: 2ef5422afb13bc37cdc5240703c54287ed400703
Appcues: b8bf2e83c90c2a000f4e9f29b0e2244c4ddc09eb

PODFILE CHECKSUM: d073e1e0b242bcec57ace36973467c46cd0f6c03

Expand Down
25 changes: 25 additions & 0 deletions Sources/AppcuesKit/Generated/Appcues+ResourceBundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Appcues+ResourceBundle.swift
// Appcues
//
// Created by Matt on 2022-01-26.
//

import Foundation

extension Appcues {
/// Bundle reference used by SwifGen.
///
/// Reference: https://github.com/SwiftGen/SwiftGen/blob/stable/Documentation/Articles/Customize-loading-of-resources.md
static let resourceBundle: Bundle = {
#if SWIFT_PACKAGE
return Bundle.module
#else
guard let url = Bundle(for: Appcues.self).url(forResource: "Appcues", withExtension: "bundle"),
let bundle = Bundle(url: url) else {
fatalError("Can't find 'Appcues' resource bundle")
}
return bundle
#endif
}()
}
18 changes: 3 additions & 15 deletions Sources/AppcuesKit/Generated/Asset+Generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal struct ImageAsset {

@available(iOS 8.0, tvOS 9.0, watchOS 2.0, macOS 10.7, *)
internal var image: Image {
let bundle = BundleToken.bundle
let bundle = Appcues.resourceBundle
#if os(iOS) || os(tvOS)
let image = Image(named: name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
Expand All @@ -56,7 +56,7 @@ internal struct ImageAsset {
#if os(iOS) || os(tvOS)
@available(iOS 8.0, tvOS 9.0, *)
internal func image(compatibleWith traitCollection: UITraitCollection) -> Image {
let bundle = BundleToken.bundle
let bundle = Appcues.resourceBundle
guard let result = Image(named: name, in: bundle, compatibleWith: traitCollection) else {
fatalError("Unable to load image asset named \(name).")
}
Expand All @@ -71,7 +71,7 @@ internal extension ImageAsset.Image {
message: "This initializer is unsafe on macOS, please use the ImageAsset.image property")
convenience init?(asset: ImageAsset) {
#if os(iOS) || os(tvOS)
let bundle = BundleToken.bundle
let bundle = Appcues.resourceBundle
self.init(named: asset.name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
self.init(named: NSImage.Name(asset.name))
Expand All @@ -80,15 +80,3 @@ internal extension ImageAsset.Image {
#endif
}
}

// swiftlint:disable convenience_type
private final class BundleToken {
static let bundle: Bundle = {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: BundleToken.self)
#endif
}()
}
// swiftlint:enable convenience_type
1 change: 1 addition & 0 deletions swiftgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ xcassets:
- templateName: swift5
params:
forceProvidesNamespaces: true
bundle: Appcues.resourceBundle
output: Asset+Generated.swift

0 comments on commit 7a24d46

Please sign in to comment.