We found a workaround for the situation described by @iRyan8, which is that the linked local package (i.e. Theme) is unable to resolve its own bundle because the paths used in the resource_bundle_accessor.swift implementation don't include the path to the bundle when it is linked via Preview.
Our "solution" is to write a replacement for resource_bundle_accessor.swift that includes a 4th path (line 17):
extension Foundation.Bundle {
static var myModule: Bundle = {
				/* The name of your local package, prepended by "LocalPackages_" */
let bundleName = "LocalPackages_Theme"
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)")
}()
}
To use this, replace references to Bundle.module with Bundle.myModule, like so:
/* Replace this... */
static let themeGreenFromXCAssets = Color("ThemeGreen", bundle: .module)
/* With this: */
static let themeGreenFromXCAssets = Color("ThemeGreen", bundle: .myModule)
Hopefully this will be addressed by an update soon. The above workaround is at least applicable for Xcode 12.3.
Post
Replies
Boosts
Views
Activity
I just noticed that I neglected to include the definition for CurrentBundleFinder in my previous reply. It can be any class, as long as it is defined in the module of the bundle you're trying to access. For example, the following is sufficient:
class CurrentBundleFinder {}
Apple Feedback filed
We're still experiencing this issue in Sandbox. We're POSTing to https://sandbox.itunes.apple.com/verifyReceipt and we consistently get 21002. Production seems okay.
Hi @MobileTen. Thanks for your comment. I'm not sure what you mean by "rewrite" the tree rather than "replace" it, though. In your linked video, one thing Alex does differently is initialize DeclSyntax nodes using explicit initializers rather than using plain strings. I haven't noticed a difference, though. When I replace return ["case bar(Bool)"] with return [DeclSyntax(try EnumCaseDeclSyntax("case bar(Int)"))], I continue to see the same issue. Can you elaborate on what I'm doing incorrectly?