Created
December 8, 2020 18:59
-
-
Save revblaze/bfe9969093fe60b181e14995b4eadfbc to your computer and use it in GitHub Desktop.
Extension: Quickly return the macOS' current system appearance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSView { | |
var hasDarkAppearance: Bool { | |
if #available(OSX 10.14, *) { | |
switch effectiveAppearance.name { | |
case .darkAqua, .vibrantDark, .accessibilityHighContrastDarkAqua, .accessibilityHighContrastVibrantDark: | |
return true | |
default: | |
return false | |
} | |
} else { | |
switch effectiveAppearance.name { | |
case .vibrantDark: | |
return true | |
default: | |
return false | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage Example
Note: When macOS toggles between modes, there is a slight delay caused by the transition time. Due to this, there is a noticeable interval in which the hierarchy correctly updates NSView's
effectiveAppearance
value.One example, that I've found to be particularly annoying, is with observing the system appearance change. Something like this:
The issue here arises when the system appearance changes and
updateAppearance()
is called:Just be aware of this. The change is not instantaneous and the
effectiveAppearance.name
has a slight delay before updating to its proper value.