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.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: