Skip to content

Instantly share code, notes, and snippets.

@mukyasa
Last active May 2, 2020 04:10
Show Gist options
  • Save mukyasa/77d2c1d67259821d97d5bf710d716cf1 to your computer and use it in GitHub Desktop.
Save mukyasa/77d2c1d67259821d97d5bf710d716cf1 to your computer and use it in GitHub Desktop.
@propertyWrapper
struct Theme {
let light: UIColor
let dark: UIColor
var wrappedValue: UIColor {
if #available(iOS 13, *) {
return UIColor { (traitCollection: UITraitCollection) -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return self.dark
} else {
return self.light
}
}
} else {
return ThemeManager.isDarkModeEnabled ? self.dark : self.light
}
}
}
enum ThemeManager {
static var isDarkModeEnabled = false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment