Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DefaultsThemeRepository
import Foundation
class DefaultsThemeRepository: ThemeRepository {
private let selectedThemeKey = "selectedThemeKey"
private let defaults = UserDefaults.standard
func load() -> Theme {
if let storedTheme = defaults.string(forKey: selectedThemeKey),
let theme = ThemeName(rawValue: storedTheme)?.theme {
return theme
} else {
return DarkTheme()
}
}
func save(_ theme: Theme) {
defaults.setValue(theme.name.rawValue, forKey: selectedThemeKey)
defaults.synchronize()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.