Replacement for NSAppearance.performAs­Current­Drawing­Appearance on macOS 10.14 and 10.15 to Fetch the Correct NSColor.cgColor

Today, I had trouble getting NSColor to work with colors from Asset catalogues when asking for its .cgColor. Since NSColor is appearance-aware, i.e. it switches light and dark mode appropriately when used directly in your views, I wondered why asking for .cgColor always returned the initial value. Say we start the app in light mode, then this is always going to be the light mode color, never dark mode. Yes, not even if you initialize the color anew using NSColor(named: ...).cgColor.

Continue reading …