I'm working with a Pod that acts as a "Theming" pod for my other apps. I would like to use multiple xcassets
files to have one xcasset by app.
For example:
- The named color
PrimaryColor
in theApp_1.xcasset
would be blue - The same color named
PrimaryColor
in theApp_2.xcasset
would be red
So when I use UIColor(named: "PrimaryColor")
, it loads the color from the right asset file.
I tried using bundles with the available init method of UIColor
:
init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)
but the Bundle I created is always nil
.
One bundle by app in the pod, with the colors assets inside:
I need to have the same color keys in the asset files but with different colors. This is why I need multiple asset files.
Then I use the following code according the app I use to get the right Bundle but it doesn't pass the first guard
.
public enum Application: String {
case app_1
case app_2
var colorsBundle: Bundle? {
let bundleName = rawValue.capitalized
let type = "bundle"
guard let bundlePath = Bundle.main.path(forResource: bundleName, ofType: type) else {
return nil
}
let colorsBundle = Bundle(path: bundlePath)
return colorsBundle
}
}