

in places where there is no associated view or view controller. Post Notifications from Main Window ChangesĪs I said, I want to have notifications, e.g. Now I can subscribe to any of the window’s view changing. NSAppearance Convenience Codeįirst, a simple boolean indicator isDarkMode would be nice:

If you want to see all code, take a look at the accomanying GitHub Gist. So even if you cannot ask your NSApplication instance for its effective appearance, you can ask your window’s main contentView. Since macOS 10.9, you have NSAppearanceCustomization.effectiveAppearance, which NSView implements. Chances are you don’t need to know more than what he explains in his posts.īut how do you react to changes to the appearance? Daniel uses KVO on NSApp.effectiveAppearance, and I had mixed results with observing changes to this attribute. (If you have other reasons, go for it! It’s always nice to drop backwards compatibility and use the new and cool stuff where possible.)įirst, check out Daniel Jalkut’s excellent series on dark mode changes. Increasing the deployment target from 10.10 to 10.13 just for the sake of easy color changes for 10.14’s dark mode is lazy.

So you limit yourself to macOS 10.13 High Sierra and newer if you use Asset Catalogs at all, even though only the light variant will be exposed there. And these don’t even work on macOS 10.11. But you cannot create adaptive NSColor objects programmatically, only via Asset Catalogs. One troublesome change is NSColors adaptability: system colors like NSColor.textBackground (white in light mode, jet black in dark mode) or idColor (an 80%ish grey color in light mode, a transparent 30%ish gray in dark mode) are very useful, but some custom interface elements need different colors to stand out visually. Because then I don’t have to implement a homebrew solution in all my writing applications. I welcome that macOS offers two modes now. Then it hit hard, and I am still tweaking my apps to look properly in Mojave’s Dark Mode. Last year, I had a full-time job from May until November and haven’t had much time to prepare for Mojave. NSAppearance Change Notifications for Dark Mode and RxSwift Subscriptions
