Skip to content

Commit

Permalink
Remove misticaCommon fix to an old Bundle.module bug
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscojrp committed Jan 13, 2025
1 parent 1df65b5 commit f653174
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions Sources/MisticaCommon/Extensions/Bundle+Mistica.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,10 @@ import Foundation
// A helper to access the framework bundle
extension Bundle {
#if SWIFT_PACKAGE
static let mistica = Bundle.misticaCommon
static let mistica = Bundle.module
#else
private final class Internal {}

static let mistica = Bundle(for: Internal.self)
#endif
}

// There is a bug when xcode automatically synthesize the bundle `Bundle.module` which makes previews to stops working when using assets from another modules.
// To fix the problem, we manually search for the bundle assets. https://developer.apple.com/forums/thread/664295
private class CurrentBundleFinder {}
private extension Bundle {
static let misticaCommon: Bundle = {
let bundleName = "Mistica_MisticaCommon"

let candidates = [
/* Bundle should be present here when the package is linked into an App. */
Bundle.main.resourceURL,
/* Bundle should be present here when the package is linked into a framework. */
Bundle(for: CurrentBundleFinder.self).resourceURL,
/* For command-line tools. */
Bundle.main.bundleURL,
/* Bundle should be present here when running previews from a different package (this is the path to "…/Debug-iphonesimulator/"). */
Bundle(for: CurrentBundleFinder.self).resourceURL?.deletingLastPathComponent().deletingLastPathComponent()
]

for candidate in candidates {
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
return bundle
}
}
fatalError("unable to find bundle named \(bundleName)")
}()
}

0 comments on commit f653174

Please sign in to comment.