Named Colors from pod only use light appearance instead of dark

Viewed 958

I have a private pod and within it is my asset catalog. There's a named color with "Any Appearance" and "Dark Appearance" values set. In my main project that's consuming the pod, I can set the colorstoryboard color selection

It even looks correct in the storyboard when I switch the interface styles between dark and light. The issue is when I then run the code, it only uses the light appearance, even in dark mode. To make it more confusing, if I set the color via code, e.g., viewDidLoad it works as expected.

let bundle = Bundle(for: PrivatePodClass.self)
let color = UIColor(named: "tableViewSectionHeader", in: bundle, compatibleWith: nil)
// Works
view.backgroundColor = color

I'm not sure if this is an issue with XCode 11 or if it's something with cocoapods, but I'd like to not be forced to set the colors via code if I don't have to.

2 Answers
contentView.backgroundColor = UIColor(named: "redColor", in: nibBundle, compatibleWith: nil)

Replace bundle with nibBundle. It worked for me. enter image description here

The problem is actually located in the modules. If your Colors.sassets file (where the named colors are defined) is not located in the main module it won't work at runtime.

The current workaround could be to copy your assets file from your external module to the main module with a script in a build phase.

I found the solution there and you'll find additional information about it: https://github.com/lechuckcaptain/TestResourcesIntoModule

Related