Currently in our project we have an internal SPM module that contains our asset catalog and an Image and Color extension to provide easy access to the different colors using static vars instead of strings.
With Xcode 15 it now generates those static vars for us automagically.
So now instead of having to define something like...
extension Color {
public static let fogmeisterRed: Color = Color("FogmeisterRed", bundle: .module)
}
You get that for free.
However, that only seems to work if the asset catalog is inside the target and has target membership to the target being built. When our asset catalog was inside the SPM module it did not (and could not) have target membership.
I've moved the asset catalog out to a shared folder now and given it target membership and now the static vars are generated. Except they're not accessible from inside the SPM modules.
So now I can do Color(.fogmeisterRed) in the target. But in the SPM modules that doesn't exist.
Is there a way to get this to work together nicely so that I can access the auto generated colors from our internal SPM modules?
In your project, you're using an internal SPM module containing an asset catalog and extensions for easy color access. With Xcode 15's automatic static variable generation for asset catalogs, you're facing issues accessing these variables from inside the SPM modules. Below is a potential solution and workaround for this issue.
Solution:
Steps:
Modify your
Package.swiftfile:.resourcesparameter to the.targetmethod.Accessing Colors in your Code:
Bundle.modulewill automatically refer to the resource bundle in the SPM package.Additional Considerations:
Workaround:
If the above solution does not work for your setup, a manual workaround is to continue creating the static variables as before:
This involves more manual work but ensures the colors are accessible from both your application and your SPM modules.